After playing with curly http://www.cliki.net/curly and liking it, I
wonder what are the other known alternative syntaxes for lambda. Like
#L etc.
Could you please post here links to such libraries.
On Mar 3, 4:14 pm, Vagif Verdi <···········@gmail.com> wrote:
> After playing with curlyhttp://www.cliki.net/curlyand liking it, I
> wonder what are the other known alternative syntaxes for lambda. Like
> #L etc.
> Could you please post here links to such libraries.
Try Haskell approach, though I haven't seen anything better than
lambda, the only improvement that I could
accept is shorter name, everything else is nicely composed into the
language.
Slobodan
On 4 Mrz., 01:14, Vagif Verdi <···········@gmail.com> wrote:
> After playing with curlyhttp://www.cliki.net/curlyand liking it, I
> wonder what are the other known alternative syntaxes for lambda. Like
> #L etc.
> Could you please post here links to such libraries.
I've sometimes used a macro named FN. Besides the shorter name it also
allows to ignore parameters named by _. So
(fn (a _ b) (list a b))
is the equivalent of
(lambda (a _ b) (declare (ignore _)) (list a b))
ciao,
Jochen
On 4 Mrz., 20:01, ·····@codeartist.org" <····@codeartist.org> wrote:
> On 4 Mrz., 01:14, Vagif Verdi <···········@gmail.com> wrote:
>
> > After playing with curlyhttp://www.cliki.net/curlyandliking it, I
> > wonder what are the other known alternative syntaxes for lambda. Like
> > #L etc.
> > Could you please post here links to such libraries.
>
> I've sometimes used a macro named FN. Besides the shorter name it also
> allows to ignore parameters named by _. So
>
> (fn (a _ b) (list a b))
>
> is the equivalent of
>
> (lambda (a _ b) (declare (ignore _)) (list a b))
And here is the code:
(defmacro fn (ll &body forms)
(let* ((ignored-symbols nil)
(ll (mapcar (lambda (v)
(if (string-equal '_ v)
(let ((v (gensym)))
(push v ignored-symbols)
v)
v))
ll)))
`(lambda ,ll
,@(when ignored-symbols
`((declare (ignore ,@ignored-symbols))))
,@forms)))
I used it (using the name -->) within an article published in the
German magazine "Toolbox". The article was called "Evolution einer
Skriptsprache" (Evolution of a Scripting Language) - I've shown how to
implement a little scripting language (a bit similar to javascript)
within 250 loc. It was published in may 2007 (Toolbox issue 3/2007).
The language is build step by step within the article. The language -
called "Fun" - was compiled directly to CL sexps so that I could use
EVAL and COMPILE to realize the interpreter and native code compiler.
Some simple Fun examples:
// function definition
function hallo (str) {
print("Hallo");
print(str);
}
// variable bindings
let r=10 {
let (A=r*r*pi, D=2*r*pi)
format(t, "Circle area: ~A~%Circle diameter: ~A~%", A, D);
let diameter = 2*r*pi
format(t,"Diameter of circle when r=~A: ~A", r, diameter);
}
// local functions
let diameter(r) 2*r*pi
format(t,"Diameter of circle when r=~A: ~A", r, diameter(10)
let (diameter(r) 2*r*pi,
area(r) r*r*pi)
format(t, "D: ~A~%A: ~A~%", diameter(10), area(10))
// multiple values
let [d,r] = floor(15,4)
format(t,"Div: ~A, ~A~%",d,r)
I used CL-YACC for the scanner and the CL readtable for the lexer. The
code above does really work since it just uses functions predefined in
Common Lisp itself (like FORMAT, * or FLOOR). It shouldn't be
difficult for an experienced CL programmer to imagine the generated CL
code behind the examples above. I didn't actually use this toy
language for more than this article but I really was quite astonished
by how easy it actually is to create a scripting language using CL
that actually doesn't look like lisp in newbies eyes. At some rainy
weekends I've also experimented a bit with lazy evaluation and
automatic currying - Common Lisp is really the perfect language
building toolkit.
ciao,
Jochen