Re: Scheme dotted pair equivalent in Clojure

2012-06-17 Thread Jonas
A very nice section of SICP[1] describes how cons/car/cdr can be built only with functions. Translated to Clojure it might look like (defn cons [a b] #(condp = % :car a :cdr b)) (defn car [cons-cell] (cons-cell :car)) (defn cdr [cons-cell] (cons-c

Re: Scheme dotted pair equivalent in Clojure

2012-06-17 Thread Mark Engelberg
In the previous post, I accidentally deleted a dot when pasting: user=> (clojure.lang.MapEntry :a 1) should have been user=> (clojure.lang.MapEntry. :a 1) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@goo

Re: Scheme dotted pair equivalent in Clojure

2012-06-17 Thread Mark Engelberg
A cons is essentially just a struct with two fields. In Clojure, it's sort of like: (defrecord Cons [car cdr]) (defn cons [x y] (Cons. x y)) (defn first [x] (:car x)) (defn rest [x] (:cdr x)) The amazing thing is that you can represent any collection of arbitrary length, just by nesting these st

Re: Scheme dotted pair equivalent in Clojure

2012-06-17 Thread Paul Stadig
On Jun 16, 11:37 am, David Nolen wrote: > Not possible in Clojure and a source of hassle in Scheme and Common Lisp. > If you have dotted pairs you can never know if you have a proper list. I'm probably missing some context, but I've heard this argument before and had a hard time understanding it.

Re: Scheme dotted pair equivalent in Clojure

2012-06-16 Thread Eric Seidel
> > I have a need to learn enough scheme to read it and write a few functions. > I came across dotted pair notation. I am trying to grok it in terms of the > only Lisp I know, Clojure. Does dotted pair notation in Scheme compare to > form in Clojure, and if so, how? > As David notes, dotted-

Re: Scheme dotted pair equivalent in Clojure

2012-06-16 Thread David Nolen
dotted pairs and cons in Scheme and CL both allow you specify an improper tail. This has some historical utility if you are using cons as a way to build up non-list data structures. Scheme and CL both provide better facilities for data structures than using cons. As far as I know lists are just co

Re: Scheme dotted pair equivalent in Clojure

2012-06-16 Thread octopusgrabbus
Thanks for answering. I am taking from your answer that I can be Lisp/Clojure-esque in Scheme and not worry about dotted pairs. That is, I can make a grid out of lists, rather than using cons to construct them. That's what I'm trying to do. On Saturday, June 16, 2012 11:35:14 AM UTC-4, octopusg

Re: Scheme dotted pair equivalent in Clojure

2012-06-16 Thread David Nolen
Not possible in Clojure and a source of hassle in Scheme and Common Lisp. If you have dotted pairs you can never know if you have a proper list. David On Sat, Jun 16, 2012 at 11:35 AM, octopusgrabbus wrote: > I have a need to learn enough scheme to read it and write a few functions. > I came acr

Scheme dotted pair equivalent in Clojure

2012-06-16 Thread octopusgrabbus
I have a need to learn enough scheme to read it and write a few functions. I came across dotted pair notation. I am trying to grok it in terms of the only Lisp I know, Clojure. Does dotted pair notation in Scheme compare to form in Clojure, and if so, how? -- You received this message becaus