Search found 127 matches
- Tue Jun 26, 2012 1:51 pm
- Forum: Common Lisp
- Topic: Programmatically name a struct
- Replies: 2
- Views: 4896
Re: Programmatically name a struct
Not sure if I understood you correctly, but (defmacro defstruct-x (name &rest rest) `(defstruct ,(intern (concatenate 'string "FOO-" (symbol-name name))) ,@rest)) (defstruct-x person (name "John" :type string)) (make-foo-person :name "James") would do it?
- Tue Jun 26, 2012 7:49 am
- Forum: Common Lisp
- Topic: Function as a parameter
- Replies: 10
- Views: 14695
Re: Function as a parameter
You want to use funcall, reduce or apply (there might be more suitable functions that call your function in some other way, like map, mapc, mapcar, mapcon etc.). If you know the number of arguments at the time you call the function, it is better to use funcall, use apply otherwise. E.g.: (defun foo ...
- Mon Jun 25, 2012 9:27 pm
- Forum: Common Lisp
- Topic: Problem in COND
- Replies: 5
- Views: 6354
Re: Problem in COND
You can't add extra parens in Lisp, like you could do it in C-like languages. In Lisp parens mean you are calling a function. So, in the line (test ("foo")) you are saying this: call function test with the result of calling function "foo", but "foo" isn't even a functio...
- Sun Jun 24, 2012 3:58 am
- Forum: Common Lisp
- Topic: Lisp newbie trying to optimize recursive algorithm, help?
- Replies: 16
- Views: 34292
Re: Lisp newbie trying to optimize recursive algorithm, help
array access in Common Lisp is slow by design [...] Well, that's something I thought I would avoid by setting the optimization setting as they were - I still don't know Lisp assembler at the level I can understand what is going on in the code it generates, but I hoped to get something similar to C ...
- Thu Jun 21, 2012 2:17 pm
- Forum: Common Lisp
- Topic: Lisp newbie trying to optimize recursive algorithm, help?
- Replies: 16
- Views: 34292
Re: Lisp newbie trying to optimize recursive algorithm, help
Well, that shouldn't happen, because it doesn't make sense, or there must be very bad array implementation in both Clozure and CLISP. I mean, you can't beat O(1) with O(n), unless you do something very silly. In fact, I suspect that as some other dynamic languages (for example JavaScript or Lua) arr...
- Thu Jun 21, 2012 7:09 am
- Forum: Common Lisp
- Topic: Lisp newbie trying to optimize recursive algorithm, help?
- Replies: 16
- Views: 34292
Re: Lisp newbie trying to optimize recursive algorithm, help
^ I think Konfusius compared the optimized array version which uses funcall against your version which he modified to not use funcall . In which case it sounds likely to be true, as the impression I've got from my tests was that the funcall ate most of the resources. One more thing to test is, as Ra...
- Wed Jun 20, 2012 2:29 pm
- Forum: Common Lisp
- Topic: Lisp newbie trying to optimize recursive algorithm, help?
- Replies: 16
- Views: 34292
Re: Lisp newbie trying to optimize recursive algorithm, help
I decided to do some full-scale testing and experimenting with your example, and, as others have said that... :roll: The most time consuming operation appears to be the funcall. http://pastebin.com/J26Nt1TV here are the results. It may be possible to optimize it further a bit by manipulating pointer...
- Tue Jun 19, 2012 9:42 am
- Forum: Common Lisp
- Topic: Lisp newbie trying to optimize recursive algorithm, help?
- Replies: 16
- Views: 34292
Re: Lisp newbie trying to optimize recursive algorithm, help
pjstrling, almost, but you did it backwards you are coercing an array to list. You wanted
or
I would prefer the second way because it allows for more precise type specification.
Code: Select all
(coerce '(1 2 3) 'vector)
Code: Select all
(make-array 3 :element-type 'fixnum :initial-contents '(1 2 3))
- Tue Jun 19, 2012 12:38 am
- Forum: Common Lisp
- Topic: Lisp newbie trying to optimize recursive algorithm, help?
- Replies: 16
- Views: 34292
Re: Lisp newbie trying to optimize recursive algorithm, help
(defun count-inversions-1 (x &optional (predicate #'<) (len (length x))) (if (or (null x) (null (cdr x))) 0 (let* ((half-a (1- (ash len -1))) (half-b (- len half-a)) (right-list (split-in-two! x))) (+ (loop for a in x summing (loop for b in right-list counting (not (funcall predicate a b)))) (c...
- Fri Jun 08, 2012 1:44 am
- Forum: Common Lisp
- Topic: SBCL - BSD Socket
- Replies: 3
- Views: 5886
Re: SBCL - BSD Socket
To add one more option to how the page may specify the character encoding - it's through HTTP header, namely "Content-Type: text/html; charset=utf-8" specifies utf-8, obviously. You also need to look for Transfer-Encoding header, because while the content may be encoded in some text coding...