develooper Front page | perl.perl6.language | Postings from March 2012

Re: How to make a new operator.

Thread Previous | Thread Next
From:
Moritz Lenz
Date:
March 21, 2012 13:21
Subject:
Re: How to make a new operator.
Message ID:
4F6A384D.5090002@faui2k3.org


On 03/21/2012 09:07 PM, Daniel Carrera wrote:
> Hello,
> 
> Is it possible to create a new range operator ':' such that:
> 
> a:b is the same as a..b  (this is the easy part)
> 
> a:b:c is a range from 'a' to 'b' by steps of 'c'. For example, 2:15:3
> == 2,5,8,11,14

That can be done by giving the new infix:<:> operator list associativity
(niecza already supports this)

> :b is the same as 0..b

create a new prefix operator... except that that prefix : is already
taken for constructing pairs

> a: is the same as a..Inf

create a postfix:<:> operator... except that postfix : is already taken
as invocant marker

> ::c is the same as 0:Inf:c

create a prefix:<::> operator. Except that this collides with existing
syntax...

> : is the same as 0..Inf

create a term:<:>.


There are hooks for all of that, but it requires you to come up with a
new syntax that doesn't collide heads-on with lots of existing grammar
rules.

Cheers,
Moritz

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About