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.

178 questions
0
votes
1 answer

Scheme Recursion/Cons

I am at the beginning of the road. I tried to understand this cons part for 2-3 hours, but I have fallen into trouble. I couldn't understand this cons part. How does it combine 'a d' according to result? (define remv (lambda (x ls) (cond …
Shmn
  • 681
  • 1
  • 4
  • 22
0
votes
1 answer

Cons function not working

I am currently trying to program a function that will cons a new element onto the top of the list, and push the rest of the list back... can anyone help me with this? My program does not work when I try to compile and run it. It goes on an infinite…
Leeho Lim
  • 19
  • 5
0
votes
1 answer

What is wrong with this OCAML function?

Here is my original code. let rec reverse l = match l with | [] -> [] | (h::t) -> (reverse t) :: h
0
votes
2 answers

Can't set windows name

So I tried to put together a window, but when I needed to name the window I told me. (Error: argument of type “const char*” is incompatible of type “LPCWSTR”) Programming for the CreateWindow method is underneath. Error should be in line 2. hwnd =…
10emil10
  • 11
  • 4
0
votes
1 answer

LISP program not small tweaks needed.

The Program is supposed to find each symbol in the List, that comes after a certain symbol. The function gets to parameters passed in. A List which could contain nested-lists and a symbol. The function has to scan thru the list and search for the…
Mark
  • 3
  • 1
0
votes
4 answers

Scala: Succinct means of conditionally consing a list

Is there a more concise way of conditionally building up a list in Scala? Here's where I'm starting: (j, k) match { case (0, 0) => List() case (j, 0) => List((c1, j)) case (0, k) => List((c2, k)) case (_, _) => List((c1, j), (c2, k)) } In…
Daniel Ashton
  • 1,388
  • 11
  • 23
0
votes
2 answers

behavior differently with two input lists with same length vs. with different lengths (Scheme)

the code "tsFunc" gets two lists as input and it will pairs each elements from two lists. It works most of cases. but then I find a bit strange behavior when I give 2 equal length of lists (e.g. '(1 2) '(3 4).... or '(a b c) '(1 2 3).... , it works…
user1915570
  • 386
  • 2
  • 7
  • 27
0
votes
2 answers

Improper vs. proper list in Scheme

The original code I try to implement.. the output should be (1.4) (2.5) from my code.. I think you all know what I try to do....this is also tail recursion practice my code (define (myFunc lst1 lst2) (if (or (null? lst1) (null? lst2)) …
user1915570
  • 386
  • 2
  • 7
  • 27
0
votes
2 answers

Scheme Cons (with #f as a second statement) output

I was wondering, If (cons (quote (a b c)) #f) gives an output (( a b c )) Then what output does this give: (cons (quote (a b c)) #t) ? Thank you
epsilon
  • 73
  • 8
0
votes
2 answers

What does (cons? list-name) do?

I was wondering what (cons? list-name) does. Does it just check that list-name is not a non-empty list? Is it just like the opposite of (empty? list-name)? If so, then is it not better to just say (empty? list-name) and then say else instead of…
0
votes
2 answers

Adding a symbol to the end of a two element list in Scheme

So far I have (define insert-3 (lambda (sym ls) (cond [(null? ls) '()] [else (cons sym (insert-3 (caadr ls)))]))) I know the caadr is wrong, because it doesn't exist in a two element list. But I don't know how to add a symbol to…
0
votes
1 answer

Counting Change in Scheme using a list of denominations

I am writing a function to count the number of ways to make change in scheme given a list of denominations and an amount. My code is as follows, but it does not work as intended. Should I be using cons instead of the + operator? Should the third…
John Friedrich
  • 343
  • 5
  • 21
0
votes
1 answer

Scheme car and cdr recursion

Can someone explain to me how the recursion works in the following function? Specifically, I am interested in what happens when the function reaches its base case. Also, why is a named let used in this code? (I am not familiar with named…
John Friedrich
  • 343
  • 5
  • 21
0
votes
2 answers

Disadvantages of using Linode VPS?

I have been looking to find a set of disadvantages of using Linode VPS. There does not seem to be any dedicated articles for what I have searched on the internet. Can anyone list some disadvantages? I'm researching the pros and cons for modern…
cwiggo
  • 2,541
  • 9
  • 44
  • 87
0
votes
1 answer

OCaml Parsing a list

I would like to parse "[a;b;c;d;e;f;g]" as "a::b::c::d::e::f::g::[]" In my part of my parser I have listOps: | combOps COLONCOLON listOps { Bin($1,Cons,$3) } | combOps SEMI listOps { Bin($1,Cons,$3) } | combOps {…
1 2 3
11
12