Monday, December 8, 2008

lisp+smalltalk+php ?

So I am closing on a a complete set of rules for my syntax:

#use . to denote end of statement
#list
:(1 2 3 4).

#boolean
($this == $that).

#block
{$x $y | $x*$y}.

#message
[$object method_call: $arg with:[object method:$sub]].

#use ; to denote "with"
[$object methoda;
methodb;
methodc].

#to emulate int objects anytime a square bracket encounters an int
#it will "cast" as intobject thus:
[1 to: 20 do: {$n | echo $n}].

#transmogrifies to
$intObject(1)->to(20)->apply('lambda_block_n');

#it may be the case that the int methods could be factored into more
#procedural form even such as for loops etc. It all depends on performance.
#but pre-optimization is definitely NOT what I am going for here

The real beauty to this is largely that we can overload operators and not have to use s-expressions to do so i.e. if I decided I wanted / to diff arrays I could easily add a method to the ArrayObject called / which accepts an array as an argument and then calls array_diff between self and the passed array:


[:(1 2 3 4 5) / :(2 4 7)]. #yields (1 3 5 7)

#transmogrified to
arrayObj(1,2,3,4,5)->__SYMB_DIV(arrayObj(1,2,3,4,5));

#hmm may get ugly with nested hash
$hash = :(a:(b:(c:true))).

#it feels unbalanced but
$hash = :(a::(b::(c:true))). #is far worse

#or I could stop being an idiot and use #
[#(1 2 3 4) each {$n | echo $n}].

#my only hesitation is as illustrated here, # is used for comments in c-alikes.

No comments: