Hi Evan,

> This is my first post. I wrote a simplified version of PicoLisp's let
> operator to try and understand the language a bit better:

OK, great! Welcome :)

> (de mylet Args
>    (let (@Var (car Args)
>          @Val (cadr Args)
>          @Body (caddr Args))
>       (macro ('((@Var) @Body) @Val))))
> : (mylet x 5 (+ x 1))
> -> 6
> Besides the fact that this definition depends on let, I have a feeling
> it isn't written the "picolisp way". How can I revise this definition
> to make it more idiomatic?

I would use 'bind'. 'bind' directly implements the lower-level
functionality of 'let':

   (de mylet Args
      (bind (cons (cons (car Args) (eval (cadr Args))))
         (run (cddr Args)) ) )

If you want to do it all "by hand", you need to save the symbol's value,
and restore it later by yourself. This, however, uses 'let' again to
save the value in 'Val':

   (de mylet Args
      (let Val (val (car Args))
         (set (car Args) (eval (cadr Args)))
            (run (cddr Args))
            (set (car Args) Val) ) ) )

If you want to avoid 'let' here, you could use a function. This is
perhaps "lispish" in the traditional way, but I wouldn't say it is
typical PicoLisp style ;-)

   (de mylet Args
      ('((Val) (set (car Args) Val) (run (cddr Args))) (cadr Args)) )

Note that for all these examples, if they were to be really used, 'Args'
should better be a transient symbol, e.g.

   (de mylet "Args"
      (bind (cons (cons (car "Args") (eval (cadr "Args"))))
         (run (cddr "Args")) ) )

- Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to