it's working like this:
(my-length '(list with four objects))
(1+ (my-length '(with four objects)))
(1+ (1+ (my-length '(four objects))))
(1+ (1+ (1+ (my-length '(objects)))))
(1+ (1+ (1+ (1+ (my-length '())))))
(1+ (1+ (1+ (1+ 0))))
p.s. you can (trace my-length) to see something like this
Search found 25 matches
- Wed Oct 19, 2011 12:59 pm
- Forum: Common Lisp
- Topic: help understanding a simple function
- Replies: 23
- Views: 30138
- Fri Nov 06, 2009 1:51 am
- Forum: Common Lisp
- Topic: Runtime compilation strategy
- Replies: 10
- Views: 14260
Re: Runtime compilation strategy
Not that I've got any experience, but instead of generating assembly directly, why not use something like http://llvm.org/, and benefit from all of the optimisers :mrgreen: and things in that project :?: It mentions some type of run-time compilation too. I looked llvm couple of days ago, problem fo...
- Thu Nov 05, 2009 12:46 am
- Forum: Common Lisp
- Topic: Runtime compilation strategy
- Replies: 10
- Views: 14260
Re: Runtime compilation strategy
Yup, take a look at ECL. When you call COMPILE-FILE in ECL, it effectively spits out a temporary .c file, invokes GCC on it, and then when you LOAD it, it dynamically loads the resulting dynamic lib. Most other Lisp compilers don't work this way, BTW. Others, like SBCL, have their own compiler/asse...
- Wed Nov 04, 2009 8:02 am
- Forum: Common Lisp
- Topic: Runtime compilation strategy
- Replies: 10
- Views: 14260
Runtime compilation strategy
I'm doing small lisp like compiler (to x86 asm) and what is bothering me is "runtime compilation", it's simple enough to do simple static C-like compiler with basic Lisp stuff (C runtime/gc and Lisp compiler emiting x86 asm) but i'm not sure how to do runtime compilation and all the proble...
- Wed Nov 04, 2009 2:34 am
- Forum: Common Lisp
- Topic: HowTo: string-parameter to use as function call
- Replies: 1
- Views: 3525
Re: HowTo: string-parameter to use as function call
(funcall (intern (string-upcase string)) arg1 arg2 ...)
- Tue Oct 13, 2009 11:31 pm
- Forum: Common Lisp
- Topic: Optimal boolean expressions evaluation
- Replies: 6
- Views: 8801
Re: Optimal boolean expressions evaluation
of course there is no mutating tests here, we can simplify this:
to
and this should lead to:
Code: Select all
(OR (AND (= A B) (= C D))
(AND (= A B) (= Y P)))
Code: Select all
(OR (AND a b)
(AND a c))
Code: Select all
(AND a (OR b c))
- Tue Oct 13, 2009 10:08 am
- Forum: Common Lisp
- Topic: Optimal boolean expressions evaluation
- Replies: 6
- Views: 8801
Re: Optimal boolean expressions evaluation
btw. i posted this here because it's part of something i'm doing in Common Lisp and i'm interested in CL solutions (also it's natural to do this in sexp) .... wiki link can help too
- Tue Oct 13, 2009 10:02 am
- Forum: Common Lisp
- Topic: Optimal boolean expressions evaluation
- Replies: 6
- Views: 8801
Optimal boolean expressions evaluation
What is known tactic for creating optimal boolean query expressions, for example if i have this query: (OR (AND (= A B) (= C D)) (AND (= A B) (= Y P))) faster evaluation would be: (AND (= A B) (OR (= C D) (= Y P))) , this is not only lisp related but it's natural to solve this in lisp form Thanks
- Sat Jan 17, 2009 5:01 am
- Forum: Common Lisp
- Topic: A "declare" form returned by macro
- Replies: 19
- Views: 34125
Re: A "declare" form returned by macro
i really like sbcl "declarations are assertions" principle, it does helps sometimes, specially for interface (it's ugly writing assert everywhere)
- Fri Jan 09, 2009 4:31 pm
- Forum: Common Lisp
- Topic: SICP Exercise related Question
- Replies: 2
- Views: 5619
Re: SICP Exercise related Question
Code: Select all
(defun a-plus-abs-b (a b)
(funcall (if (> b 0) '+ '-) a b))