lisp

Error in conditional (cond …) script-fu

我与影子孤独终老i 提交于 2019-12-13 04:48:37
问题 I'm trying to do a script-fu and I'm using a cond statement theoretically correct, but it always gives the error "Error: ( : 1) illegal function ". This is the code: (define (script-fu-prueba edicionInteractiva) (let* ( (cond ( (equal? edicionInteractiva "Interactivo") (edicionInteractiva RUN-INTERACTIVE) ) ( (equal? edicionInteractiva "No interactivo") (edicionInteractiva RUN-NONINTERACTIVE) ) ) ) ) ) (script-fu-register "script-fu-prueba" "<Image>/Filters/PRUEBA" "Prueba" "Author"

Parse string with “read” and ignore package namespaces

≯℡__Kan透↙ 提交于 2019-12-13 03:50:36
问题 I am writing a program that opens a lisp file, calls "read" on the stream until the stream is empty, and does things with the lists it collects. This was working quite nicely until I discovered that "read" will perform package lookup, for instance if it encounters some-package:foo it will complain that Package SOME-PACKAGE does not exist. Here is an example showing what I mean: (read (make-string-input-stream "(list 'foo :foo some-package:foo)")) So I now I would like one of three things:

Insert-everywhere procedure

痞子三分冷 提交于 2019-12-13 03:00:56
问题 I am trying to write a procedure that takes a a symbol and a list and inserts the symbol at every possible position inside the given list (thus generating a list of lists). I have coded the following definitions, which I must implement: 1 (define (insert-at pos elmt lst) (if (empty? lst) (list elmt) (if (= 1 pos) (cons elmt lst) (cons (first lst) (insert-at (- pos 1) elmt (rest lst)))))) 2 (define (generate-all-pos start end) (if (= start end) (list end) (cons start (generate-all-pos (+ start

Finding the diagonals of square matrix made from lists

巧了我就是萌 提交于 2019-12-13 02:32:24
问题 I am currently trying to define a function that takes a list of lists, models that list as a square matrix and returns the diagonal of said matrix. For example, input ((a b c) (d e f) (g h i)) gives (a e i) . I have a vague idea of how to go about solving this (taking the last element of the last list then the second to last element of the second to last list etc.) but I am not really sure of how to go about programming this in Scheme. I would appreciate it if somebody could point me in the

Pass by value confusion in Scheme

末鹿安然 提交于 2019-12-13 02:27:45
问题 Consider the following procedure taken from SICP: (define (make-withdraw balance) (lambda (amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds"))) Suppose I say: (define x (make-withdraw 100)) make-withdraw returns a procedure ( (lambda (amount) ... ) ) inside a new environment called e2 (enclosing the binding for the variable balance ), and binds that procedure to x in the global frame. Now, say I call: (f x) where (define (f y) (y 25)) 1 . I

What does this Lisp code mean?

陌路散爱 提交于 2019-12-13 02:23:54
问题 In https://www.thc.org/root/phun/unmaintain.html Lisp is regarded such that "LISP is a dream language for the writer of unmaintainable code." and then proceeds to provide some code examples. These were regarded as somthing [that] "can literally be read and understood in about a second by anyone who knows lisp." on a recent Hacker News comment. My question is, as someone with only a very small bit of experience in Clojure — what do they mean? (lambda (*<8-]= *<8-[= ) (or *<8-]= *<8-[= )) I

Embedded ECL lisp error handling

爱⌒轻易说出口 提交于 2019-12-13 01:46:18
问题 Task: Embed ECL lisp in my project, setup error handling and detailed error reporting (where occurred, kind of error, etc.) I tried to do that such way: cl_def_c_function_va( c_string_to_object("SYSTEM:UNIVERSAL-ERROR-HANDLER"), LispErrorHandler); ECL have no documentation on its embedded API and no documentation on error handling... Can you suggest how to implement that? 回答1: There is no global error handler because this is not the Common Lisp philosophy. If you want to handle errors, do it

Counter variable in LISP

那年仲夏 提交于 2019-12-13 01:34:09
问题 Define the function 'occ' that takes a list L and a symbol A and counts the occurance of symbol A in L. Example: (occ '(((s) o ) d) 'f) --> 0 What i have gotten so far: (defun occ(list a) (setq counter 0) ;Checks if the given list is has an nested list (if (consp list) ; Breaking the list down atom by atom and recursing (or (occ a (car list)) (occ a (cdr list))) ; checks if symbols are the same (if(eq a list) (setq counter(1+ counter))))) However My output keep saying Nil instead of

CLISP : Check if two elements are in order one after another in a list

巧了我就是萌 提交于 2019-12-13 01:18:54
问题 I have a list L=(1 j 3 k 4 h 5 n 6 w) I need to do a function Verify that will verify if the first atom is before the 2nd. I want to verify this: > Verify(3 k) result should return > T // because atom '3' is before atom 'k' And in this case : >Verify(h 4) result should return > NIL // because atom 'h' is after atom '4' I have to check position of each element and compare positions 回答1: What dialect of Lisp are you using? Here are some pointers on how to derive a solution, fill-in the blanks:

Difference between the 'Standard method combination' and 'Simple method combination' in CLOS

蹲街弑〆低调 提交于 2019-12-13 01:12:58
问题 I've been studying the Common Lisp Object Protocol (CLOS) and I came across one doubt. Does anybody what is the meaning of the 'Standard method combination' and 'Simple method combination' in CLOS? And in the 'Simple method combination' what does it mean to have a 'list' method combination? (defgeneric what-are-you? (obj) (:method-combination list :most-specific-last)) (defmethod what-are-you? list ((obj fixnum)) "I am a FIXNUM") (defmethod what-are-you? list ((obj float)) "I am a FLOAT")