Talk:Cons: Difference between revisions
Appearance
Content deleted Content added
→snoc: new section |
Sebfumaster (talk | contribs) |
||
Line 8: | Line 8: | ||
: I'm not clear on how you could think they aren't right or how they might "seem" not to work, unless you simply don't understand the notation or the subject matter -- in which case you should just say so. cons returns a closure that applies a function to the two values. car invokes the closure with a function that returns the first value, and cdr invokes the closure with a function that returns the second value -- it couldn't be much simpler or more straightforward. -- [[Special:Contributions/98.108.225.155|98.108.225.155]] ([[User talk:98.108.225.155|talk]]) 07:25, 19 November 2010 (UTC) |
: I'm not clear on how you could think they aren't right or how they might "seem" not to work, unless you simply don't understand the notation or the subject matter -- in which case you should just say so. cons returns a closure that applies a function to the two values. car invokes the closure with a function that returns the first value, and cdr invokes the closure with a function that returns the second value -- it couldn't be much simpler or more straightforward. -- [[Special:Contributions/98.108.225.155|98.108.225.155]] ([[User talk:98.108.225.155|talk]]) 07:25, 19 November 2010 (UTC) |
||
: I'm new to scheme, but just trying the cons definition in common music (a scheme) did not do the same thing as cons. specifically: |
|||
: (define (mycons x y) |
|||
: (lambda (m) (m x y))) |
|||
: and then (mycons 3 5) returns #<lambda (m)>. How is this returned function supposed to be called? |
|||
: this is not the same as (cons 3 5), which returns the dotted pair (3 . 5). At any rate some clarification or reference would be helpful to those new to thinking functionally such as myself |
|||
== snoc == |
== snoc == |
Revision as of 05:42, 16 September 2014
Computer science Unassessed | |||||||||||||||||
|
Not fundamental
Could somebody check those definitions? They don't look right and they don't seem to work. 84.191.247.10 (talk) 23:26, 19 August 2008 (UTC)
- They look fine to me. Tried them out under guile and they worked as expected. (Named them mycons, mycar, and mycdr because I didn’t want to clobber the built-in functions.) --Malirath (talk) 17:40, 31 March 2009 (UTC)
- I'm not clear on how you could think they aren't right or how they might "seem" not to work, unless you simply don't understand the notation or the subject matter -- in which case you should just say so. cons returns a closure that applies a function to the two values. car invokes the closure with a function that returns the first value, and cdr invokes the closure with a function that returns the second value -- it couldn't be much simpler or more straightforward. -- 98.108.225.155 (talk) 07:25, 19 November 2010 (UTC)
- I'm new to scheme, but just trying the cons definition in common music (a scheme) did not do the same thing as cons. specifically:
- (define (mycons x y)
- (lambda (m) (m x y)))
- and then (mycons 3 5) returns #<lambda (m)>. How is this returned function supposed to be called?
- this is not the same as (cons 3 5), which returns the dotted pair (3 . 5). At any rate some clarification or reference would be helpful to those new to thinking functionally such as myself
snoc
I'm tempted to remove the recent addition of Cons#Snoc. Cons
is a primitve operation, but snoc
is not. (snoc a b)
is a cute name for what Lisp would refer to as (with args reversed) (append b (list a))
or (nconc b (cons a NIL))
. It is not a common operation and seems to have little merit. Append is a clearer name, and real code might use a trailing pointer. If snoc needs to be explained, then it can be explained there instead of redirecting here. Glrx (talk) 00:46, 16 January 2014 (UTC)