Some blogger was showing de-structuring in Clojure (a Java based LISP). Just wanted to share how easy this is in newLISP using 'unify' and 'bind':
(set 'struct '((one "two") 3 (four ("five"))))
(set 'pattern '((A B) C (D (E))))
; de-structure
(bind (unify pattern struct))
A → one
B → "two"
C → 3
D → four
E → "five"
'unify' returns an association list and 'bind' binds the associations
I don't get that - what's de-structuring for? (no entry in wikipedia...). But I like to see unify being used - I've yet to use it in my stuff!
(PS: I think Fanda is a Clojure user now...- saw his name crop up on a Clojure mailing list...)
Some things in CloJure can be done simply (more simply) in NewLISP
e.g.:
;;; CloJure ;;;
; (defn my-zipmap [keys vals]
; (loop
; [map {}
; ks (seq keys)
; vs (seq vals)]
; (if (and ks vs)
; (recur (assoc map (first ks) (first vs))
; (rest ks)
; (rest vs))
; map)))
;
; (my-zipmap [:a :b :c] [1 2 3])
; => (:b 2, :c 3, :a 1)
;;; NewLISP ;;;
(println (map list '(a b c) '(1 2 3)))
; => ((a 1) (b 2) (c 3))
... or maybe I did not undestand at all ?
P.S.: Quote from: "cormullion"
I don't get that - what's de-structuring for?
neither do I

(//%3C/s%3E%3CURL%20url=%22http://smileys.sur-la-toile.com/repository/Cligne/b_wink.gif%22%3E%3CLINK_TEXT%20text=%22http://smileys.sur-la-toile.com/reposit%20...%20b_wink.gif%22%3Ehttp://smileys.sur-la-toile.com/repository/Cligne/b_wink.gif%3C/LINK_TEXT%3E%3C/URL%3E%3Ce%3E)
I think it's from this blog: "Some notes about Clojure"
//http://items.sjbach.com/16/some-notes-about-clojure
reddit programming: comment link. (//http)
If you understand it enough, you can taunt er. "comment" about newLISP's version at both of above links ;)
-- xytroxon
Quote from: "xytroxon"
If you understand it enough, you can taunt er. "comment" about newLISP's version at both of above links ;)
;) always tempting! But then I liked what Rich Hickey (Mr Clojure) said in a comment on another blog somewhere - if you want others to respect your language, then respect their's too...
I like design of the clojure web site (clojure.org) as well. (Lutz - perhaps it's time to retire all those HTML CENTER tags on newlisp.org?)
Thanks for the links, I understand a little better now what it is about ...
... and I find Lutz's example (in NewLISP) clearer and more readable (and more "Lispic") than those in CloJure.
CloJure
(def flat "flat")
(def tree '(("one" ("two")) "three" ((("four")))))
;; Simple binding (like Common Lisp's LET*).
(let [var1 flat
var2 tree]
(list var1 var2))
-> ("flat" (("one" ("two")) "three" ((("four")))))
;; Full destructuring.
(let [var1 flat
[[a [b]] c [[[d]]]] tree]
(list var1 a b c d))
-> ("flat" "one" "two" "three" "four")
NewLISP
(set 'flatten "flat")
(set 'tree '(("one" ("two")) "three" ((("four")))))
;; Simple binding (like Common Lisp's LET*)
(let (var1 flatten
var2 tree)
(list var1 var2))
;-> ("flat" ("one" ("two")) "three" ((("four"))))
;; Full destructuring.
(let (var1 flatten)
(bind (unify '((A (B)) C (((D)))) tree))
(list var1 A B C D))
;-> ("flat" "one" "two" "three" "four")
N.B.:(flat (list flatten tree)) seems simpler for full destructuring ;-)
That gave rise to play with unify and above all to understand it.
(And I did not finish understanding yet)
;-)
Quote from: "cormullion"
Quote from: "xytroxon"
If you understand it enough, you can taunt er. "comment" about newLISP's version at both of above links ;)
;) always tempting! But then I liked what Rich Hickey (Mr Clojure) said in a comment on another blog somewhere - if you want others to respect your language, then respect their's too...
That's why I said you need to understand it first!
Clojure has a lot of "Why did they want or have to do it that way?" changes.
Differences with other Lisps:
//http://clojure.org/lisps
So it is interesting to study... But hard to challenge the language without a lot more experience using Clojure.
Quote from: "cormullion"
I like design of the clojure web site (clojure.org) as well. (Lutz - perhaps it's time to retire all those HTML CENTER tags on newlisp.org?)
For looking like it doesn't need to use javascript, it has too much javascript for my taste ;)
-- xytroxon
Quote from: "cormullion"
;) always tempting! But then I liked what Rich Hickey (Mr Clojure) said in a comment on another blog somewhere - if you want others to respect your language, then respect their's too...
Comparing can be also a token of respect, because of the interest that we take to learn and understand another language ... :-)