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
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,345
  • 8
  • 38
  • 82
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 {…
0
votes
1 answer

Higher-Order Procedure - pair construction (cons, car, cdr)

i need to create this procedures: my-cons, my-car, my-cdr in Scheme. It should work like this: (define p1 (my-cons 3 8)) (p1 #t) 3 (p1 #f) 8 (my-car p1) 3 (my-cdr p1) 8 now, I have only this: (define my-cons (lambda (x y) (cons x y) (let ((a (car…
kelly
  • 409
  • 2
  • 9
  • 24
0
votes
2 answers

How can i remove the side effects of cons?

I can get the odd elements of a list using the following code: (define (odds lis) (cond ((null? lis) '()) ((not (list? lis)) (quote (Usage: odds(list)))) ((null? (car lis)) '()) ((= (length lis) 1) (car lis)) (else (cons (car…
user1822789
  • 45
  • 2
  • 6
0
votes
2 answers

Getting values not list for cons in lisp

I'm making a function in scheme(lisp) in which I need to cons a list with it reverse, as below: (cons list (cdr (reverse list))) consider I have this list '(0 1 2), the desired output would be: (0 1 2 1 0) but I get: ((0 1 2) 1 0) is there any…
Netwave
  • 23,907
  • 4
  • 31
  • 58
0
votes
1 answer

NSString to const char * convert with Greek characters

I'm trying to convert an NSString which contains a greek word to a const char. I'm trying to convert the string with UTF-8 encoding which is for greek language and when i'm logging the char out, it has junk in it. Please a little help here.. //this…
Kostas Papa
  • 5
  • 1
  • 4
-1
votes
1 answer

Creating a dictionary in racket

Write the function build-author-index that consumes a(listof Book) and a list of unique authors (Strings). The function produces an AuthorIndex where the keys are the authors consumed (in the same order) and the values are the titles of all books by…
Java Coder
  • 119
  • 11
-1
votes
2 answers

Concatenating list elements - Scheme

If i have a scheme code that generates the following result: (i'm using cons) '((1 . 0) . 0) How can i take this, and just simply display 100 as if it were just one integer number and not a list presented with those dots and…
Gambit2007
  • 1,834
  • 4
  • 27
  • 53
-1
votes
1 answer

Use cons in front of arguments in racket/scheme

I know cons is for building pairs, like (cons 2 (cons 3 empty)), but I don't understand the code here that use cons after empty. Isn't cons built for numbers? How can cons take 2 arguments? If they can take 2 arguments, how does it evaluate them?…
-1
votes
3 answers

LISP: take an arbitrary s-expression and reverse every cons node (car and cdr of a node) recursively

So in lisp a list is a collection of cons nodes, each node has two parts to it. The car of the node and the cdr of that node, how would I go about reversing each cons node?
user3011240
  • 77
  • 2
  • 8
-2
votes
1 answer

What exactly CONS of the language do?

What exactly CONS of the language scheme/LISP do? like in this function for example: (DEFINE (guess list1 list2) (COND ((NULL? list1) '()) ((member (CAR list1) list2) (CONS (CAR list1) (guess (CDR list1) list2))) (ELSE (guess (CDR list1)…
-2
votes
1 answer

How is each of the things different in cons of LISP?

These are the outputs of different combinations of arguments to cons. I just started learning lisp. Can someone help me understand these ? Break 80 [81]> (CONS '(A) 'B) ((A) . B) Break 80 [81]> (CONS '(A) '(B)) ((A) B) Break 80 [81]> (CONS 'A 'B)…
shrinidhisondur
  • 731
  • 7
  • 18
-3
votes
1 answer

LISP - what does CONS need to work?

I had this question in an exam, how would you solve it? CONS is a fundamental Common Lisp function. Which functionality must the Common Lisp environment provide to make it work? What would happen to this code without it? (defun test(n l1 l2) (when…
-4
votes
4 answers

Counting vowel and consonant in a string

int total = 0; int wordCount = 0, index = 0; var vowels = new HashSet { 'a', 'e', 'i', 'o', 'u' }; var consonants = new HashSet { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p',…
1 2 3
10
11