Questions tagged [cons]

The fundamental operation for constructing data in LISP

In the dialects of LISP (including Common Lisp, Scheme, Clojure) the cons procedure is the basic building block for constructing a memory object which holds two values (or pointers to values). The objects created by a call to cons are referred to as (cons) cells or as (cons) pairs.

164 questions
9
votes
1 answer

Erlang: which pattern matching is more efficient (lists)?

I'm going through "Pragmatic Programming Erlang" where there is a function defined like this: split("\r\n\r\n" ++ T, L) -> {reverse(L), T}; split([H|T], L) -> split(T, [H|L]); split([], _) -> more. What interests me is first match, namely…
cji
  • 6,158
  • 2
  • 18
  • 16
9
votes
3 answers

What does [a|b|c] evaluate to in SWI-Prolog?

The pipe operator in prolog returns one or more atomic Heads and a Tail list. ?- [a,b,c] = [a,b|[c]]. true. Nesting multiple pipes in a single match can be done similar to this: ?- [a,b,c] = [a|[b|[c]]]. true. What does the statement [a|b|c] infer…
Ambrose
  • 1,210
  • 12
  • 18
8
votes
6 answers

LISP cons in python

Is there an equivalent of cons in Python? (any version above 2.5) If so, is it built in? Or do I need easy_install do get a module?
tekknolagi
  • 9,371
  • 20
  • 66
  • 112
7
votes
1 answer

Why is line-seq returning clojure.lang.Cons instead of clojure.lang.LazySeq?

According to the ClojureDocs entry for line-seq (http://clojuredocs.org/clojure_core/clojure.core/line-seq) and the accepted answer for the Stack question (In Clojure 1.3, How to read and write a file), line-seq should return a lazy seq when passed…
user1922460
5
votes
2 answers

fst and 3-tuple in fsharp

Do you know the nicest way to make this work : let toTableau2D (seqinit:seq<'a*'b*'c>) = let myfst = fun (a,b,c) -> a let myscd = fun (a,b,c) -> b let mytrd = fun (a,b,c) -> c let inputd = seqinit |> groupBy2 myfst myscd there must be…
nicolas
  • 8,208
  • 3
  • 32
  • 69
5
votes
4 answers

32-bit or 64-bit application on 64-bit OS?

We are developing a swing application written by Java which requires only about 128MB memory, and in the short future I don't see it will require much more memory like 4GB. Previously we provide always 3 different releases, one for 32-bit Windows,…
Wayne Xu
  • 53
  • 4
5
votes
4 answers

How to do ((A.B).(C.D)) in lisp

I'm trying to figure out how to do this using cons: ((A . B) . (C . D)) where (A . B) and (C . D) are in each cons cell I've tried doing this (cons (cons 'a 'b) (cons 'c 'd)) but it gives me this: ((A.B) C . D) I also tried this: (cons (cons 'a 'b)…
5
votes
2 answers

perl6 functions similar to "car cdr cons" in scheme?

I really love perl6 and scheme. I am wondering if there are functions in perl6 that are similar to the "cons, car, cdr" functions in scheme? What I have been doing feels cumbersome: sub cons($a, $aList) { return flat($a, $aList); } # sometimes flat…
lisprogtor
  • 5,057
  • 8
  • 14
5
votes
1 answer

Where is Reason's cons (::) operator?

The cons (::) operator is a fundamental part of 1) writing recursive list functions in OCaml and similar languages, and 2) pattern matching on lists. However, I can't find anything in Reason's documentation concerning cons, and in the REPL, this…
jayelm
  • 5,880
  • 4
  • 35
  • 53
5
votes
0 answers

Statically typed well-formed cons list in C#

I've asked myself a stupid question and have been wracking my brain for a few hours now with no result. Let's say you want to implement a cons cell in C# for whatever reason (Greenspun's tenth rule should be enough). Since it's in C#, you want it to…
Alexey
  • 1,248
  • 9
  • 24
5
votes
4 answers

Difference between multiple values and plain tuples in Racket?

What is the difference between values and list or cons in Racket or Scheme? When is it better to use one over the other? For example, what would be the disadvantage if quotient/remainder returns (cons _ _) rather than (values _ _)?
Alex
  • 1,094
  • 7
  • 13
5
votes
1 answer

in clojure language what <'a> really is

actually i am trying to perfectly understand clojure and particularly symbols (def a 1) (type a) ;;=>java.lang.Long (type 'a) ;;=>clojure.lang.Symbol I know that type is a function so its arguments get evaluated first so i perfectly understand why…
user3228423
  • 115
  • 3
4
votes
3 answers

cons :: operator for sequences in F#?

Is there a better code that does not need to transform the sequence into a list ? let rec addentry map keys = match keys with | ((i,j) :: tail) -> Map.add (i,j) ((inputd.[i]).[j]) (addentry map tail) | ([]) -> map addentry Map.empty…
nicolas
  • 8,208
  • 3
  • 32
  • 69
4
votes
5 answers

Lisp, cons and (number . number) difference

What is the difference between (cons 2 3) and '(2 . 3) in Lisp?
David Degea
  • 1,178
  • 2
  • 10
  • 16
4
votes
3 answers

Is it still inadvisable to define constructors and selectors as cons, car, and cdr?

Structure and Interpretation of Computer Programs has the following footnote: Another way to define the selectors and constructor is (define make-rat cons) (define numer car) (define denom cdr) The first definition associates the name make-rat with…
J. Mini
  • 1,288
  • 4
  • 23
1
2
3
10 11