freenode/#lisp - IRC Chatlog
Search
21:30:32
Xach
I do that quite a bit and sometimes I forget how a slot is initialized. I should start writing describe-object methods that mention how a particular slot is populated.
21:39:44
anlsh
When I do (safe-square (incf *a*)), I expect it to return the (once-only (x) `(* ,x ,x)), and once-only returns '(+ 3 4) no matter what, so I expect (safe-square (incf *a*)) => (+ 3 4)
21:39:56
no-defun-allowed
If you're looking to bind x, then you need to create a let form around the body.
21:41:39
no-defun-allowed
Remember that macros function just like normal functions and are subject to normal evaluation rules, they just happen to output code and have slightly different lambda lists.
21:43:56
anlsh
See here's where I'm confused: lisp functions always return the result of evaluating their last form, correct? (aside from some when some special operators are used)
21:46:14
anlsh
so when evaluating the once-only, the result is `(+ 3 4), so I guess I'm wondering why that isn't just passed up
21:53:08
no-defun-allowed
Well yes, `(+ 3 4) is evaluated in the macro body to yield (+ 3 4), which is then evaluated by the code containing the macro call.
21:58:15
anlsh
I see, I guess not evaluating a macro post-expansions would just make their return values useless haha
22:00:14
anlsh
So am I correct that, aside from a few things like destructuring parameters lists and &body, the forms (labels ((op-name <some-definition>)) (eval (op-name args))) are (macrolet ((op-name <some-definition>)) (op-name args)) are pretty much equivalent?
22:01:14
no-defun-allowed
I'm not sure, macros can get some insight on the environment they're evaluated in. Also, the compiler can optimise macros better.
22:01:43
anlsh
I mean I guess that macros can do critical stuff like control evaluation order which you can't do with the function definition, but the point being the extra eval when written as function call
22:02:15
pjb
anlsh: For example: (defun foo (x) (return-from foo (+ 42 x)) 33) The last form is 33. But the result is the result of evaluating (+ 42 x).
22:06:12
pjb
anlsh: (+ 3 7) is never evaluated. The result of `(+ 3 4), which is (+ 3 4) is evaluated at run-time, after the macroexpansions have been done.
22:07:07
pjb
Now, in (defmacro once-only ((&rest names) &body body) `(+ 3 4)) (defmacro safe-square (x) (once-only (x) `(* ,x ,x)))
22:07:40
pjb
(once-only (x) `(* ,x ,x)) is expanded when the safe-square macro is compiled, and the returned expansion (+ 3 4) is evaluated when the safe-square macro itself is expanded.
22:08:41
pjb
(macroexpand '(once-only (x) `(* ,x ,x))) #| --> (+ 3 4) ; t |# (macroexpand '(safe-square (incf *x*))) #| --> 7 ; t |#
22:09:23
pjb
after the macroexpansion of the call to once-only, it's like if (defmacro safe-square (x) (+ 3 4)) had been written.
22:09:50
pjb
When expanding (safe-square (incf *x*)), (+ 3 4) is evaluated returning 7, and this is the expansion returned by safe-square.
22:10:56
anlsh
I see, realizing macroexpansion consists of both an expansion step and an evaluation step clears things up a lot
22:12:13
pjb
But the resulting expansion that is returned by the macro function is not evaluated AT ALL!
22:13:42
pjb
python476: not currently. Coarsely, I've seen job offers about once every 4 or 5 years, not more.
22:14:35
pjb
python476: the best is to start your own company, and use lisp to develop solutions for your customers, like dim does with his sql tools.
22:16:10
python476
maybe later, when I have a stable situation I'll do [common]lisp project in-house
22:17:06
pjb
For example, when I have to write code in C, I write it in CL first, debug it, and when it's good, I translate it to C.
22:17:43
pjb
Or since I use emacs, I may write emacs lisp code to help me produce the code in the programming languages I need to use.
22:18:46
python476
I sense that this dynamic prototyping for near optimal solution to optimized rewrite is becoming a skill to spread
22:18:47
pjb
python476: I recently improved my LINC translator: https://github.com/informatimago/lisp/tree/master/languages/linc which let me generate C code from sexps.
22:19:06
python476
read a few articles about people ditching straight c++ for python or else on first drafts
22:22:53
pjb
https://github.com/informatimago/lisp/blob/master/languages/linc/test-statements.sexpc generates https://pastebin.com/DWE8Yk4L
0:09:38
no-defun-allowed
Fortunately I don't think I need that kind of function now but it does sound handy to know.
3:43:10
beach
minion: Memo for jmercouris: Because it only removes from the end, whereas subseq can simultaneously remove from the start and from the end.
6:31:19
manualcrank
performance is usually average, but occasionally awful (vs same algorithm in another lang)
6:35:34
no-defun-allowed
Though it will slow down the program a bit, it will show you the slow function calls.
6:39:04
no-defun-allowed
The interface looks like TRACE, use (sb-profile:profile foo bar baz) to profile foo bar and baz, sb-profile:unprofile to unprofile, and (sb-profile:report) to see the report
6:44:50
no-defun-allowed
I don't know how the problem goes, but could you try to generate some input data?
6:46:56
shka__
manualcrank: without profiler it is imposible to tell what's going on (unless algorithm sucks)
6:47:47
manualcrank
again, though, direct translation of algo to c++ = 0.06s (like all the other c++ soln's)
6:48:49
shka__
manualcrank: i would generate data, put it in the vector, eleminate read-lines and see how this works then
6:49:18
shka__
he is already reserving proper size of the hash-table so i don't think that realocations are a problem
6:51:20
xantoz
is there some way to re-use the memory when reading the strings in lisp? (in C I would just use stack-alloced fixed-size arrays for current and previous word)
6:52:14
no-defun-allowed
read-sequence? Still don't think that'd be the bottleneck and you should investigate further.
6:52:22
xantoz
I was thinking that read-line would create lots of transient objects, but I might be wront
6:53:48
shka__
manualcrank: if words are short (8 chars) you probabbly won't come close to C++ anyway but i agree that 1.2s is suspicious
6:56:55
shka__
i you want some words https://github.com/sirherrbatka/cl-data-structures/blob/master/test/files/words.txt