Hi Rick,

thanks for the ideas :)

However, as Mike Pechkin wrote, I do also believe that such a construct
is rather useless.

The examples are too simple. They can be easily rewritten as:

> (if-let X 13 (- X 1) 0)   #-> 12

   (if 13 (dec @) 0)

> (if-let X 13 (- X 1))     #-> 12  # you can leave off the Else clause.

   (if 13 (dec @))

> (if-let X 0 (+ 42 X) -1)  #-> 42  # because 0 is "truthy".

   (if 0 (+ @ 42) -1)

and so on ..

Can you provide an example where it is shorter with 'if-let' than with
existing flow functions?

Note that you can always do

   (if (condition)
      (let X @
         (do-something 1) )
      (do-something 2)
      (do-something 3) )


> # A definition
> (de if-let "Args"
>   ## Better than anaphoric `if` because you can name the test result
>   ## yourself.
>   (let ((@Pattern "Test" @Then @Else) "Args"
>         @Test-Result (eval "Test"))
>     (eval
>      (fill
>       '(if @Test-Result
>            (let (@Pattern @Test-Result)
>              @Then)
>            @Else)
>       '(@Pattern @Test-Result @Then @Else)))))

This is a very un-PicoLisp-ish solution. It is a huge overhead to
rebuild the whole expression with 'fill' each time it is called.

Instead, you need to interprete it directly:

   (de if-let "Args"
      (if (eval (cadr "Args"))
         (bind (car "Args")
            (set (car "Args") @)
            (eval  (caddr "Args")) )
         (run (cdddr "Args")) ) )

   : (if-let X (* 3 4) (inc X) "Nope")
   -> 13

   : (if-let X NIL (inc X) "Nope")
   -> "Nope"

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

Reply via email to