lisp

How to check if an item returned is a list itself?

对着背影说爱祢 提交于 2019-12-11 10:32:20
问题 Morning - I'm trying to see if there is a way to check if an item returned from a list is a list itself. For example (elt '(a (b c) d) 1) Is there a way to check that the item returned is a list? I tried using length, (length (elt '(a (b c) d) 1)) but if it is given an item that is not a list it throws an error. In short I'm looking for a way to go through each element of a list and check if it is a list or not. Thank you 回答1: the listp tells you that : (listp (elt '(a (b c) d) 1)) 来源: https:

Flatten once procedure

穿精又带淫゛_ 提交于 2019-12-11 09:49:03
问题 I'm having a bit of a struggle with coding a procedure that flattens a list once, i.e (flatten-once '((b) (c f) ((d)(e)))) would produce '(b c f (d) (e))) . I checked up on a few sources on how the standard flatten procedure works but it implements functions that are not included in the intermediate student with lambda language form I'm required to use. As far as I have it figured out a foldr would be somewhat helpful and have managed to get this (define (flatten-once lst) (cond [(empty? lst)

not able to find package when running from SLIME, but from command line is ok

天大地大妈咪最大 提交于 2019-12-11 08:51:33
问题 I'm running the teapot example from cl-opengl package. The only changes I've made are loading the required packages. It works fine when executed from unix shell ( sbcl --load "3.cl" ), but when I try to compile and load it through SLIME ( C-c C-k ) i get the error about package GLUT not found. Curiously, the compiler chokes on the (defclass glut-teapot-window (glut:window) . What gives??? Here's a screenshot of what happens Here's the code for 3.cl. ;;;; -*- Mode: lisp; indent-tabs-mode: nil

How to find the package of a class in lisp?

ε祈祈猫儿з 提交于 2019-12-11 08:14:34
问题 Suppose I want to find out in which package a class is defined, e.g. say (defclass x ()()) is defined in p1. One way could be to get the package via (symbol-package 'x). the problem with this solution is that x is exported in a different package p2. Any other suggestions? 回答1: As Rainer Joswig said, classes aren't defined in packages; symbols have packages and the name of a class is a symbol. If you want to know the value of *PACKAGE* at the time the class definition read, compiled, or loaded

delete sublist by element occurrence (Scheme)

谁说我不能喝 提交于 2019-12-11 07:43:28
问题 How I could remove a sublist by searching only one elem from it. For example, let's have the list: ( (pacific (atlanta ohaio) (NY LI)) (atlanta (pacific blue) (ohaio green)) ) And I want to remove "pacific" from the list and to get: ( (pacific (atlanta ohaio) (NY LI)) (atlanta (ohaio green)) ) Any ideas would be greatly appreciated :). 回答1: The criteria for deleting an element from the input list is not stated clearly in the question. This will work for the example shown: (define lst '(

Lisp macros quotation implementation in JavaScript

一笑奈何 提交于 2019-12-11 07:36:52
问题 I have basic scheme like lisp in JavaScript and have problem with backquote and quote macros, they evaluate symbols if they are at first element of the array like > `(foo 10) give error foo not found it work for code like this > (define x '(1 2 3)) > (print `(1 2 ,@x 4 5)) my eval function look like this: function evaluate(code, env) { env = env || global_env; var value; if (typeof code === 'undefined') { return; } var first = code.car; var rest = code.cdr; if (first instanceof Pair) { value

Zip function in typed racket with rest arguments

那年仲夏 提交于 2019-12-11 07:26:30
问题 I'm struggling with the syntax for a function that zips together any number of lists. I currently have: (define (zip . [lsts : (Listof Any) *]) (apply map (inst list Any) lsts)) Which causes the following error when evaluated: Error: struct:exn:fail:syntax /Applications/Racket v6.6/collects/racket/private/kw.rkt:929:25: Type Checker: Bad arguments to function in `apply': Domains: (-> a b ... b c) (Listof a) (Listof b) ... b (-> a c) (Pairof a (Listof a)) Arguments: (-> Any * (Listof Any))

Why does this defun closure not behave the same as the defparameter closure?

有些话、适合烂在心里 提交于 2019-12-11 07:26:07
问题 Consider these two: (defparameter *lfn* (let ((count 0)) #'(lambda () (incf count)))) (defun testclosure () (let ((count 0)) #'(lambda () (incf count)))) Why do they behave differently: CL-USER> (funcall (testclosure)) 1 CL-USER> (funcall (testclosure)) 1 CL-USER> (funcall *lfn*) 1 CL-USER> (funcall *lfn*) 2 count is closed over in the defparameter version but not in the defun version. Why is this? 回答1: Sylwester's answer explains this very well, but in a case an example with more explicit

CLISP Terminal error: Invalid byte sequence

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 07:01:38
问题 i have a problem while loading my source file inside terminal using clisp. if i execute the following command to load the file: (load #p "filename.lisp") it gives me the following error: SYSTEM::LINE-COMMENT-READER: Invalid byte sequence #xE0 #xA0 #x20 in CHARSET:UTF-8 conversion can someone please tell me what i need to do in order to load the file? thank you. 回答1: Your file is encoded with ISO-8859-1: $ file filename.lisp filename.lisp: ISO-8859 text, with no line terminators Based on CLISP

Is “Lisp-1 vs Lisp-2” relevant in a language with static types?

断了今生、忘了曾经 提交于 2019-12-11 06:59:52
问题 (This is a CS-theory type of question; I hope that's acceptable.) The "Lisp-1 vs Lisp-2" debate is about whether the namespace of functions should be distinct from the namespace of all other variables, and it's relevant in dynamically typed languages that allow the programmer to pass around functions as values. Lisp-1 languages (such as Scheme) have one namespace, so you can't have both a function named f and also an integer named f (one would shadow the other, just like two integers named f