Jump to content

Talk:Cons: Difference between revisions

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
Content deleted Content added
→‎snoc: new section
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

WikiProject iconComputer science Unassessed
WikiProject iconThis article is within the scope of WikiProject Computer science, a collaborative effort to improve the coverage of Computer science related articles on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
???This article has not yet received a rating on Wikipedia's content assessment scale.
???This article has not yet received a rating on the project's importance scale.
Things you can help WikiProject Computer science with:

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)[reply]

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)[reply]
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)[reply]
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)[reply]