cons

On Scheme cons and dots notation

好久不见. 提交于 2021-01-27 17:28:19
问题 Given #;> (cons (cons 1 2) 3) ((1 . 2) . 3) When we try #;> (cons 3 (cons 1 2)) (3 1 . 2) What governs where the . is used? What would the memory representation of these constructs be? 回答1: Scheme implementations usually print things that look like lists in list form: -> (cons 1 (cons 2 '())) '(1 2) In your example, (cons 3 (cons 1 2)) would be a list if it weren't for the last 2 . So your implementation makes a best effort to print it as a list until the 2 . The other example does not

clojure: no cons cells

不问归期 提交于 2020-05-28 12:44:27
问题 i heard that clojure does not have cons cells as of most lisp languages. does that mean a clojure list does not end with an empty list? could anyone explain what that exactly means? 回答1: Lisp provides a primitive cons data structure and a notation for it. See John McCarthy, Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, 1960, Chapter 3, Recursive Functions of Symbolic Expressions. That chapter introduces: Symbolic expressions made of atoms and pairs of

clojure: no cons cells

a 夏天 提交于 2020-05-28 12:44:03
问题 i heard that clojure does not have cons cells as of most lisp languages. does that mean a clojure list does not end with an empty list? could anyone explain what that exactly means? 回答1: Lisp provides a primitive cons data structure and a notation for it. See John McCarthy, Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, 1960, Chapter 3, Recursive Functions of Symbolic Expressions. That chapter introduces: Symbolic expressions made of atoms and pairs of

Trying to print a triangle recursively in lisp

ε祈祈猫儿з 提交于 2020-01-25 08:57:07
问题 Trying to print a triangle recursively in lisp. I get an overflow but I don't know from where. Mind you I am new to Lisp programming. (defun triangle (n) (if (not (oddp n))(progn (print "This is not an odd integer") (return-from triangle n))) (if (< n 1) '()) (setf lst (cons (car(list n)) (triangle (- n 2)))) (print lst)) (triangle 7) 回答1: Let's review some parts of your code. (if (not (oddp n)) (progn (print ...) (return-from ...))) When you have an if with only one branch, think about using

How to efficiently reference count cons cells (detecting cycles)?

一世执手 提交于 2020-01-05 08:37:33
问题 I need to make some sort of liblisp (in C11), and it will need to handle the basic functions, pretty much like what libobjc does for the Objective-C language. Edit I'm rewritting the question to something less generic. I got an implementation like this: typedef struct cons { void *car, *cdr; } *cons_t; cons_t cons_init(void *, void *); void *cons_get_car(cons_t); void *cons_get_cdr(cons_t); void cons_set_car(cons_t, void *); void cons_set_cdr(cons_t, void *); void cons_free(cons_t); bool cons

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

谁说我不能喝 提交于 2020-01-02 03:31:08
问题 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 a java.io.BufferedReader. However when I test this in the REPL, the type is listed as clojure.lang.Cons. See the code below: => (ns stack-question (:require [clojure.java.io :as io])) nil => (type (line-seq (io/reader "test-file.txt"))) clojure

NSString to const char * convert with Greek characters

折月煮酒 提交于 2019-12-30 14:44:14
问题 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 is the greek word NSString *letter = textFieldLetter.text; //NSString to const char conversion for the sql query const char *cLetter = (const char *)[letter cStringUsingEncoding:NSUTF8StringEncoding]; //this contains junk! NSLog(@"letter: %s"

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

你离开我真会死。 提交于 2019-12-22 06:03:19
问题 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, one for 32-bit Linux and another for 64-bit Linux, with an installer which has JRE included. The 64-bit version was not used by anyone until couple of weeks ago, and an OutOfMemoryException was reported because the application consumes about 40-50%

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

谁说胖子不能爱 提交于 2019-12-22 06:01:33
问题 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, one for 32-bit Linux and another for 64-bit Linux, with an installer which has JRE included. The 64-bit version was not used by anyone until couple of weeks ago, and an OutOfMemoryException was reported because the application consumes about 40-50%

How does “Cons” work in Lisp?

我是研究僧i 提交于 2019-12-21 07:54:55
问题 I was studying Lisp and I am not experienced in Lisp programming. In a part of my studies I encountered the below examples: > (cons ‘a ‘(a b)) ----> (A A B) > (cons ‘(a b) ‘a) ----> ((A B).A) I was wondering why when we have (cons ‘a ‘(a b)) the response is (A A B) and why when we change it a little and put the 'a after (a b) , the response is a dotted list like ((A B).A) ? What is the difference between the first code line and the second one? What is going on behind these codes? 回答1: It's