I like the idea of `if-let` (which you can see in Clojure[1], and
probably other languages).  It's like anaphoric `if`[2] but better
because you can name the result of the conditional test.  (Intentional
variable capture is always best when you are controlling the variable
names; not having a name forced upon you.)

I think this is the idea Alex had for `let?`[3]; however it seems
`let?` doesn't work with pil64 pattern bindings (i.e. destructuring
binds) and `let?` doesn't seem to have the possibility of an else
clause (either that or my imagination and overall pil knowledge
suffers enough not to see such a possibility -- Alex will tell me :).

Anyway, please feel comment, criticize, etc.  If you do, I will learn
something.  Thanks!  --Rick

# Usages
(if-let X 13 (- X 1) 0)   #-> 12
(if-let X 13 (- X 1))     #-> 12  # you can leave off the Else clause.
(if-let X '() (- X 1))    #-> NIL # b/c no Else clause and false condition.
(if-let X 0 (+ 42 X) -1)  #-> 42  # because 0 is "truthy".
(if-let (X Y) (1 2) Y 42) #-> 2   # pattern binding for pil64.
(if-let (X Y) 1 Y 42)     #-> NIL # because the pattern binding failed.
(if-let (X Y) '() Y "test failed") #-> "test failed"
(if-let (X Y) NIL Y "test failed") #-> "test failed"

# 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)))))

____
[1] http://clojuredocs.org/clojure.core/if-let
[2] http://www.bookshelf.jp/texi/onlisp/onlisp_15.html#SEC100
[3] http://software-lab.de/doc/refL.html#let?
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to