lisp

Understanding bound and free variables in LISP

二次信任 提交于 2019-12-10 19:29:35
问题 I'm reading SICP , and the topic of bound and free variables has come up. However, I am confused about it. Does the term "bound variables" only apply to variables that are formal parameters? In addition, the text says that a procedure definition "binds" its formal parameters. This confuses me with the fact that some people say that we "bind" a value to a variable. Obviously, the term seems to mean different things when we're talking about different types of variables. Could someone clear up

How to mutate global variable passed to and mutated inside function?

℡╲_俬逩灬. 提交于 2019-12-10 19:08:41
问题 I'm wondering how to permanently alter the value of a global variable from inside a function, without using the variable's name inside the function, i.e.: (defvar *test1* 5) (defun inctest (x) (incf x)) (inctest *test1*) ;after it runs, *test1* is still 5, not 6 According to this: if the object passed to a function is mutable and you change it in the function, the changes will be visible to the caller since both the caller and the callee will be referencing the same object. Is that not what I

How to export slots and accessors from Lisp classes?

痴心易碎 提交于 2019-12-10 17:56:16
问题 This is my class's package: (in-package :cl-user) (defpackage foo (:use :cl) (:export :bar)) (in-package :foo) (defclass bar () (baz)) I can create an instance of bar in package cl-user . CL-USER> (defvar f) F CL-USER> (setf f (make-instance 'foo:bar)) #<FOO:BAR {10044340C3}> But I can't access the member baz . Calling slot-value like so ... CL-USER> (slot-value f 'baz) ... results in this error message: When attempting to read the slot's value (slot-value), the slot BAZ is missing from the

How do I jump out of a function in Lisp?

蹲街弑〆低调 提交于 2019-12-10 17:47:00
问题 Is it possible in (Common) Lisp to jump to another function instead of call another? I mean, that the current function is broken and another is called, without jumping back through thousands of functions, as if I'd decide myself if tail call optimization is done, even if it is not the tail. I'm not sure if "(return-from fn x)" does, what I want. Example: (defun fn (x) (when x (princ x) (jump 'fn (cdr x))) (rest)) 'jump' should be like calling the following function without saving the position

How to compile Clisp 2.46?

做~自己de王妃 提交于 2019-12-10 17:21:59
问题 When I try to compile the newest version of Clisp on Ubuntu 8.04 I always get this error after running configure: Configure findings: FFI: no (user requested: default) readline: yes (user requested: yes) libsigsegv: no, consider installing GNU libsigsegv ./configure: libsigsegv was not detected, thus some features, such as generational garbage collection and stack overflow detection in interpreted Lisp code cannot be provided. Please do this: mkdir tools; cd tools; prefix=`pwd`/i686-pc-linux

Get list of user created variables

十年热恋 提交于 2019-12-10 17:11:13
问题 I want to get a list of all variables that I have created in a lisp session. I think that this should be possible by looking at all symbols interned in common-lisp-user. But how can I get such a list? 回答1: To get bound variables only from cl-user you iterate all bound symbols with do-symbols and exclude the symbols, that are imported from other packages: (let ((external-symbols (mapcan (lambda (pkg) (let (rez) (do-symbols (s pkg rez) (push s rez)))) (package-use-list (find-package 'cl-user)))

'cdadr' on nested data list in lisp

帅比萌擦擦* 提交于 2019-12-10 17:09:14
问题 While studying cons , cdr and car to handle lists I tried following : (cadr '('(1) '(2))) '(2) which gives the second item in the list as expected. Whereas following gives : (cdadr '('(1) '(2))) ((2)) How is data being concerted to code and still not giving error? How was this evaluated? cdr on '(2) should give nil, which is does. Why not above? [I am new to both clisp and stackoverflow so pardon me.] 回答1: quote is a special operator which returns its single unevaluated argument. The form

Quicksort in LISP

心不动则不痛 提交于 2019-12-10 16:16:54
问题 I am trying to do a quicksort using LISP but I am having trouble with my functions output. (defun qsort (L) (cond ((null L) nil) (t(append (qsort (list< (car L) (cdr L))) (cons (car L) nil) (qsort (list>= (car L) (cdr L))))))) (defun list< (a b) (cond (( or(null a)(null b) nil)) (( < a (car b)) (list< a (cdr b))) (t(cons (car b) (list< a (cdr b)))))) (defun list>= (a b) (cond (( or( null a)(null b) nil)) (( >= a (car b)) (list> a (cdr b))) (t(cons (car b) (list> a (cdr b)))))) My problem

What is the difference between let and let* in Scheme?

纵饮孤独 提交于 2019-12-10 16:13:23
问题 I am writting a script for GIMP and using let* as it was in a sample I took. But it seems to be just a lambda sugar exactly like let . Why are they different? What is the difference between them? 回答1: They are different in the order in which variables are bound. Consider this for example: > (let ((a 1)(b (+ a 2))) b) This code will FAIL because b requires a , which has not been defined before. It is defined, in the same let , but Scheme will take all your let definitions as only one statement

LISP or Haskell [closed]

烈酒焚心 提交于 2019-12-10 16:01:52
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . LISP or Haskell, I need to learn functional programming, but I heard that lisp is very old, any advice between those two languages ?