Re: The `if-let` construct

2015-08-09 Thread Alexander Burger
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


Re: The `if-let` construct

2015-08-09 Thread Mike Pechkin
hi all,

I totally dont like it. I vote.
All this useless.
Can you write here #Usage examples of (if-let) in current language feature
set?
Coder already have all needed, like in forth.
If coder want, it have all required to implement this by himself.
Like reduce and -> from clojure I've used to emulate for 4clojure tasks.

(de reduce ("Fun" "Lst")
   (let "A" (car "Lst")
  (for "N" (cdr "Lst")
 (setq "A" ("Fun" "A" "N")) )
  "A" ) )
(de -> ("X" . "A")
   (for "Form" "A"
  (setq "X" (apply (car "Form") (cdr "Form") "X")) ) )


Code is ok, but useless inside pl feature set.

p.s. Create wiki page and collect code as useful snippets.





On Mon, Aug 10, 2015 at 5:10 AM, Rick Hanson  wrote:

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


Re: The `if-let` construct

2015-08-09 Thread Rick Hanson
A subtle change in the definition.  Added two quote marks.

(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)
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe