Search found 62 matches

by Konfusius
Tue Nov 13, 2012 1:18 am
Forum: Common Lisp
Topic: Replacing a function in an expression
Replies: 20
Views: 42011

Re: Replacing a function in an expression

Of course they can. But implementation-specific special forms must have macro-expansions...so if you fully-macroexpand, there can't be any implementation-specific special forms remaining -- just functions and standard special forms. The ANSI spec says that ... An implementation is free to implement...
by Konfusius
Mon Nov 12, 2012 9:20 am
Forum: Common Lisp
Topic: Replacing a function in an expression
Replies: 20
Views: 42011

Re: Replacing a function in an expression

Unfortunately there is no implementation independent way to do this since every implementations has it's own special forms. But usually the number of special forms is small wich makes it feasible to write different versions for different implementations. No. The special forms/operators are defined ...
by Konfusius
Sun Nov 11, 2012 1:21 pm
Forum: Common Lisp
Topic: Replacing a function in an expression
Replies: 20
Views: 42011

Re: Replacing a function in an expression

Goheeca wrote:Konfusius your solution doesn't work for me, I get an output the same as an input.
I've corrected the bug. It should work, now. But your solution is better.
by Konfusius
Sun Nov 11, 2012 4:57 am
Forum: Common Lisp
Topic: Replacing a function in an expression
Replies: 20
Views: 42011

Re: Replacing a function in an expression

(defun do-replacement (expr) (setf expr (macroexpand expr)) (cond ((atom expr) expr) ((eq 'list (car expr)) (cons 'my-list (mapcar #'do-replacement (cdr expr)))) ((special-operator-p (car expr)) (case (car expr) ; special forms need special handling (quote expr) (let (list* 'let (mapcar (lambda (bi...
by Konfusius
Thu Nov 01, 2012 3:46 am
Forum: Common Lisp
Topic: match pattern
Replies: 1
Views: 5914

Re: match pattern

(define-condition pattern-maching-failed (error) ()) (defun rxvarp (exp) (if (and (consp exp) (= 2 (length exp)) (eq '? (car exp)) (symbolp (cadr exp))) (cadr exp))) (defun bind-rxvar (var exp bind) (let ((ent (assoc var bind))) (if ent (if (equalp (cdr ent) exp) bind (error 'pattern-maching-failed...
by Konfusius
Sun Oct 28, 2012 3:21 am
Forum: Common Lisp
Topic: argument-passing vs. dynamic variable lookup
Replies: 3
Views: 5959

Re: argument-passing vs. dynamic variable lookup

Variable lookup is done only in interpreted Lisps. In modern compiled Lisps the "lookup" cost of dynamic and lexical variables is the same as for global and local variables in C++.
by Konfusius
Wed Oct 24, 2012 6:07 am
Forum: Common Lisp
Topic: Binary search tree obscure code...
Replies: 5
Views: 19198

Re: Binary search tree obscure code...

The problem is your print-function which prints only the root node of the tree.
by Konfusius
Sat Oct 20, 2012 2:06 pm
Forum: Common Lisp
Topic: strange error with mapcan and quote.
Replies: 1
Views: 4148

Re: strange error with mapcan and quote.

Mapcan operates destructively on the lists returned by the function. Because your function returns a literal list mapcan operates destructively on a literal object. The error will go away if you replace '(even) by (list 'even).
by Konfusius
Fri Oct 19, 2012 8:42 am
Forum: Common Lisp
Topic: Behaviour of EVAL inside LET
Replies: 14
Views: 27391

Re: Behaviour of EVAL inside LET

Eval can be useful if you want to write your own repl or interpreter. But in 99% of the cases where beginners tend to use eval there is a better solution using functional objects and funcall. It also executes much faster than eval. (setf z 666) (let ((z 14)) (print z) (funcall #'(lambda () (setf www...
by Konfusius
Wed Oct 17, 2012 1:04 pm
Forum: Common Lisp
Topic: Adding element to a sorted list
Replies: 9
Views: 18810

Re: Adding element to a sorted list

Code: Select all

(defun sorted-push (lst n &key (test #'<) (key #'identity))
  (if (null lst)
	(cons n nil)
	(if (funcall test (funcall key n) (funcall key (car lst)))
	  (cons n lst)
	  (cons (car lst) (sorted-push (cdr lst) n :test test :key key)))))

(sorted-push '((1 . 2) (5 . 6)) '(3 . 4) :key #'cdr)