Search found 613 matches

by ramarren
Tue Jul 03, 2012 9:53 am
Forum: Common Lisp
Topic: Writing a macro to define methods
Replies: 3
Views: 8289

Re: Writing a macro to define methods

It is technically doable. If you are confused about backquotes and commas then remember that they are purely syntax, you can always write it out using standard list manipulation functions, which is more verbose but sometimes more clear. But, although that it is hard to tell without knowing in more d...
by ramarren
Wed Jun 20, 2012 7:16 am
Forum: Common Lisp
Topic: Lisp newbie trying to optimize recursive algorithm, help?
Replies: 16
Views: 34560

Re: Lisp newbie trying to optimize recursive algorithm, help

Actually, a lot of the problem here is not with FUNCALL itself but with the fact that FUNCALL screens optimizations. If you pass as a predicate not #'<, which is generic multi-argument function, but (lambda (a b) (declare (fixnum a b)) (< a b)) it will reduce the time by more that half alone. Of cou...
by ramarren
Sat Jun 16, 2012 7:13 am
Forum: Common Lisp
Topic: Separate lisp and foreign name for cffi defcstruct?
Replies: 3
Views: 6641

Re: Separate lisp and foreign name for cffi defcstruct?

Is it the case that the defcstruct name can be arbitrary and is not referenced against the exported c symbols? I am reasonably sure that this is in fact the case. CFFI in general doesn't enforce type safety of foreign data, you can refer to any piece of memory you own as any type. And C doesn't exp...
by ramarren
Fri Jun 15, 2012 4:29 am
Forum: Common Lisp
Topic: difference between cffi mem-ref/mem-aref
Replies: 2
Views: 4631

Re: difference between cffi mem-ref/mem-aref

The manual is quite explicit on the difference: The mem-aref function is similar to mem-ref but will automatically calculate the offset from an index. To elaborate, the optional argument to those functions is treated differently, in mem-ref the offset is in bytes, but in mem-aref the offset is the i...
by ramarren
Sun Jun 10, 2012 5:17 am
Forum: Homework
Topic: Code for calculating difference of sets not working
Replies: 4
Views: 11109

Re: Code for calculating difference of sets not working

I think I've got rid of them now although I'm still using the setq command within the while-loop, because I can't quite figure out where I should put the end-bracket of let otherwise Sorry, I misspoke, you shouldn't create variables with SETQ, because they will be set as global variables and leak o...
by ramarren
Sun Jun 10, 2012 12:06 am
Forum: Homework
Topic: Code for calculating difference of sets not working
Replies: 4
Views: 11109

Re: Code for calculating difference of sets not working

In Lisp all parentheses are usually meaningful, they are not just grouping/block delimiters. In your case you have superfluous parentheses around the else branch of IF and around the body of WHILE. This makes the system interpret those as function calls, and an entire expression does not name a func...
by ramarren
Wed Jun 06, 2012 5:08 am
Forum: Homework
Topic: Why the function doesn't work?
Replies: 2
Views: 7821

Re: Why the function doesn't work?

It seems to work. Are you sure you defined the function as included, and not some other version?
by ramarren
Thu May 10, 2012 12:25 pm
Forum: Common Lisp
Topic: (Need to go deeper!) macroexpansion confusion
Replies: 3
Views: 5755

Re: (Need to go deeper!) macroexpansion confusion

If you have a large quasiquoted block in the macro often you can extract it into a function, and then use a macro to just wrap a body with a lambda like this: (defun call-with-words-in-string (s whites thunk) (do ((end 0 (1+ end)) (start 0) (word) (len 0)) ((= end (1+ (length s)))) (if (or (= end (l...
by ramarren
Mon May 07, 2012 5:06 am
Forum: Common Lisp
Topic: Store a function in a variable
Replies: 1
Views: 3748

Re: Store a function in a variable

In Common Lisp you can access the function value of a binding with FUNCTION special operator or create an anonymous function with LAMBDA.

You can read a more explanatory explanation than the specification in Practical Common Lisp.
by ramarren
Mon May 07, 2012 5:03 am
Forum: Common Lisp
Topic: Multiple conditions in an if statement?
Replies: 2
Views: 6677

Re: Multiple conditions in an if statement?

Use the AND macro. This is fairly trivial question, perhaps reading a book like Practical Common Lisp would be faster than waiting for an answer on a forum (relevant chapter).