lisp

How to write a scheme function that takes two lists and returns four lists

谁说我不能喝 提交于 2019-11-29 08:13:34
I have 2 lists of elements '(a b c) '(d b f) and want to find differences, union, and intersection in one result. Is that possible? How? I wrote a member function that checks if there is a car of the first list in the second list, but I can't throw a member to the new list. (define (checkResult lis1 lis2) (cond........... )) (checkresult '( a b c) '(d b f)) My result should be (( a c) (d f) (a b c d f) (b)) . Like others have said, all you need to do is create separate functions to compute the intersection, union, and subtraction of the two sets, and call them from checkresult: (define

In common-lisp, how do I modify part of a list parameter from within a function without changing the original list?

有些话、适合烂在心里 提交于 2019-11-29 07:18:09
I'm trying to pass a list to a function in Lisp, and change the contents of that list within the function without affecting the original list. I've read that Lisp is pass-by-value, and it's true, but there is something else going on that I don't quite understand. For example, this code works as expected: (defun test () (setf original '(a b c)) (modify original) (print original)) (defun modify (n) (setf n '(x y z)) n) If you call (test), it prints (a b c) even though (modify) returns (x y z). However, it doesn't work that way if you try to change just part of the list. I assume this has

In Lisp, how many inputs can the + function actually have?

元气小坏坏 提交于 2019-11-29 07:05:55
I'm relatively new to Lisp, and I was wondering if there really is an upper limit to the "+" function. (I guess this applies to all the other arithmetic functions "-", "/" etc.) Yes, there is an upper limit, but the exact upper limit is implementation-dependent. You're guaranteed to be able to pass at least 50, but it all depends. If you need to sum a list, you're probably better off with (reduce #'+ list) , that should give you a much better scalability than any other method. Common Lisp HyperSpec has some more info. When it comes to value ranges there are two distinct cases, floats and

F# equivalent to Eval

你。 提交于 2019-11-29 06:05:43
Is there an F# equivalent to eval? My intent is to have my app load a small code sample from a file and essentially let file = "c:\mysample" let sample = loadFromFile file let results = eval(sample) I am new to F# and trying to figure out some of the limitations before I apply it to a project. Thank you Tomas Petricek There is no function that would allow you to do this directly. However, when you want to compile an F# source file programatically, you can invoke the F# compiler from your application. The easiest way to do this is to use F# CodeDOM provider, which is available as part of the F#

Using string object as a hash key in Common Lisp

房东的猫 提交于 2019-11-29 05:32:12
I'm trying to create a "dictionary" type - ie hash table with a string as a key. Is this possible or wise in Lisp? I noticed that this works as expected: > (setq table (make-hash-table)) #<HASH-TABLE :TEST EQL size 0/60 #x91AFA46> > (setf (gethash 1 table) "one") "one" > (gethash 1 table) "one" However, the following does not: > (setq table (make-hash-table)) #<HASH-TABLE :TEST EQL size 0/60 #x91AFA0E> > table #<HASH-TABLE :TEST EQL size 0/60 #x91AFA0E> > (setf (gethash "one" table) 1) 1 > (gethash "one" table) NIL NIL You need to make hash-table that uses 'equal instead if 'eql. 'eql doesn't

How to see docstrings and other symbol information in Common Lisp REPL?

只愿长相守 提交于 2019-11-29 05:24:30
问题 I'm completely new to CL, and I'd like to learn how to read documentation strings and get other help information from the REPL. Something like help(symbol) in Python, or symbol? in iPython, or :t and :i in Haskell's GHCi. So, given a symbol name, I'd like to be able to know: what kind of value it is bound to, if any (a function, a variable, none at all) if it is a function or a macro, then what are its positional arguments if it has a docstring, show it what package or file it is coming from

continuation in common lisp by macros — regarding an implemetation in OnLisp

最后都变了- 提交于 2019-11-29 04:09:42
问题 In On Lisp, p. 267, Paul Graham provides an implementation of continuation passing macros: (setq *cont* #'identity) (defmacro =lambda (parms &body body) `#'(lambda (*cont* ,@parms) ,@body)) (defmacro =defun (name parms &body body) (let ((f (intern (concatenate 'string "=" (symbol-name name))))) `(progn (defmacro ,name ,parms `(,',f *cont* ,,@parms)) (defun ,f (*cont* ,@parms) ,@body)))) (defmacro =bind (parms expr &body body) `(let ((*cont* #'(lambda ,parms ,@body))) ,expr)) (defmacro =values

The tool for visual programming

左心房为你撑大大i 提交于 2019-11-29 04:07:50
问题 I need the tool for graphical representing of work flow in a program (like electronic circuits are described with graphical representation). The representation has to be like the following: functions are boxes and arrows between boxes are "messages". Like this: alt text http://img372.imageshack.us/img372/8471/functionsqv0.png This picture shows the following: (c (a) (b)) Where parameters of c() are named as d and e. On C it would be void c( someType1 d, someType2 e ); someType1 a( void );

Swapping elements in a Common Lisp list

谁说我不能喝 提交于 2019-11-29 03:47:36
Is there a Common Lisp function that will swap two elements in a list given their indices and return the modified list? You can use rotatef : (rotatef (nth i lst) (nth j lst)) Of course, list indexing can be expensive (costing O( size of list )), so if you do this with any regularity, you'd rather want to use an array: (rotatef (aref arr i) (aref arr j)) aaronasterling I would avoid indexing into the list twice by using nthcdr to get the cdr of the cons cell containing the first element that you want to swap and then use elt to get the remaining element out of the sublist. This means that you

Using Let in Scheme

荒凉一梦 提交于 2019-11-29 03:00:05
问题 I want to write a program to find the roots of the quadratic equation in Scheme. I used LET for certain bindings. (define roots-with-let (λ (a b c) (let ((4ac (* 4 a c)) (2a (* 2 a)) (discriminant (sqrt ( - (* b b) (4ac))))) (cons ( / ( + (- b) discriminant) 2a) ( / ( - (- b) discriminant) 2a))))) I defined the discriminant with 4ac since I did not want (* 4 a c) . Even though I have defined (4ac (* 4 a c)) , it is giving me this error: expand: unbound identifier in module in: 4ac . My