freenode/#lisp - IRC Chatlog
Search
2:53:48
Josh_2
Thanks :) Just double checking as I'm putting this into a presentation that's a large chunk of my grade
2:54:26
Bike
idealized vector access is an addition to get the memory address followed by an access of the memory address. list access is a memory access for each cons cell traversed, etc
3:09:36
dmiles
something i dont get is on the page http://www.lispworks.com/reference/HyperSpec/Body/f_mexp_.htm .. #'MACROEXPAND uses "&optional env" ... but for a macro lambdalist, one uses "&environment env" like (defmacro expand-1 (form &environment env) ... ) ?
3:13:11
Bike
if you have (defmacro expand-1 (form &environment env) ...), (expand-1 foo) is legal and (expand-1 foo bar) is not.
3:15:45
Bike
macroexpand having an &optional env is different from a macro having an &environment env. the former allows an environment to be explicitly provided by the programmer. the latter just means that the macroexpander wants to use the environment the macro form is in.
3:19:54
dmiles
.. so (defmarco expand-1 arg &optional (env env-supplied-p) &environment env) might have been used if expand-1 wanted to be like macroexpand-1 ?
3:20:39
Bike
but if i understand it correctly, no. macroexpand-1 doesn't know about the environment it's called in.
3:23:52
dmiles
but the (defmacro my-expand-1 (arg &optional penv &environment env) .. (let ((env-i-use (if penv penv env))) ... some code using env-i-use .. )
3:25:22
Bike
if you have an &environment parameter, within the body of the macroexpander it will be bound to the environment the macro form is in. Let me give you an example.
3:26:23
dmiles
(ah, i had sorta assumed the &environment env was just so the body would have a convience var named 'env for the global env :P)
3:26:48
Bike
now say we have (defmacro pexpand (form &environment env) (print (macroexpand-1 form env)) nil)
3:28:12
Bike
In contrast, say you have (defmacro dumb-pexpand (form) (print (macroexpand-1 form)) nil)
3:29:11
Bike
then (dumb-pexpand (dumb)) => 4, but (macrolet ((dumb () 5)) (dumb-pexpand (dumb)) => 4. Because it doesn't use the local environment, it just uses the global one.
3:33:26
dmiles
FLET and MACROLET are scoped in a lexical enviroment.. the way they get decared is locally.. but that would place a limit on where they can be used
3:35:19
Bike
The environment accessible with &environment contains information about these lexical scopes.
3:35:25
dmiles
why i call it a limit.. is if you use them within the scope you dont need to think about passing env arround
3:35:55
Bike
If macroexpand doesn't receive an environment parameter, it uses the global environment, which has no information about lexical bindings as produced by flet or macrolet.
3:36:12
Bike
As such, macroexpanders that need to expand other macros would behave badly if there was no &environment available.
3:36:45
dmiles
i might have to set up a testcase in the next couple houirs once i fix my current trouble
3:37:28
dmiles
what i was wondering is if other macroexpansions still use just the global enviroment even inside the lexical scope
3:39:25
Bike
Is English not your first language? I have a hard time understanding what you try to convey.
3:43:50
dmiles
(the question about if macrolet can define macros that get used inside the same lexical scope but not actualyl defined in the same scope))
3:46:12
loke
dmiles: The answer is that the unexpanded macro is returned from the first macro call. Then the compiler looks at the result of that first macro, and repeats by expanding the second macro.
3:46:59
dmiles
Bike: yes.. so i am trying to confirm that wheter or not the macrolet should be invisible to other macros that get called by other macros
3:48:27
Bike
You have (defun eval (form env) ...). The first thing that ... does is macroexpand: just (macroexpand form env). macroexpand repeatedly calls macroexpand-1, as you probably know.
3:49:15
Bike
macroexpand-1 is something like (defun macroexpand-1 (form &optional env) (if (consp form) (let ((mf (macro-function (first form) env))) (if mf (funcall *macroexpand-hook* mf form env) ...
3:50:03
Bike
In other words, it looks up the macro definition in the environment it's passed, and if it's there, calls macroexpand-hook. macroexpand-hook is basically funcall, so the macroexpander function is called with two arguments, the form to expand, and the environment.
3:50:18
Bike
If the definition of the macro had an &environment, that's the environment it gets. if not it's ignored.
3:51:01
Bike
Now, if the form passed to eval is a macrolet form, like say (macrolet ((foo ...)) ...body...), all it does is recursively evaluate body in a new environment that includes the definition of foo.
3:51:41
Bike
like (defun eval (form env) ... (if (eq (first form) 'macrolet) ... (eval (cddr form) (augment-with-macros (second form) env)) ...
3:56:53
dmiles
i would have assumed that macrolet created a "special macro" with the meaning as "special" in "special vars" that as they are being (i'll stick with special vars (forget macros for the moment) as theire bindings are availbel shadowed in the global enviironment)
3:57:31
dmiles
i was thinking that macrolet would shadow any of its uses at the same level of its env
3:57:58
dmiles
(meaning it would not be usefull tp ass env to subsequent calls.. as the shadow macro would be present)
4:55:24
Josh_2
This is not really lisp related although it is something I did in lisp :P anyways Quicksort has an average performance of O(n log n) and I have a real time of 15ms, how do I check if my sorting algorithm is hitting it's ideal time or not?
4:55:52
Josh_2
There is the point that it is doing more than just sorting so that's going to cause some issues
4:58:14
beach
Josh_2: O(n log n) means that it is less than or equal to k*n*log(n) for some k, but you don't know the k.
4:58:57
beach
Josh_2: So no matter what your timing shows, you can always find a k that makes it true.
4:59:31
Josh_2
Ahh okay, well it is always sorting the same number of elements, but the variation in the elements change, causing quicksort to become faster than bucket sort
5:00:12
beach
Still, it is always going to be on the average O(n log n) for some k, no matter how many inputs you give it.
5:00:57
Josh_2
Alrighty, I'll mention that the average is correct, but that the change in bucketsort is obvious
5:02:12
beach
Mentioning that the average is correct is not going to give any information, because the average is always correct for any finite number of test cases.
5:05:39
Josh_2
I already dicked my grade by doing sorting algorithms. My own fault for wasting a load of time because I didn't read the spec properly..
10:30:22
knobo
I'd like to do patternmatching to get the most spesific result. Something like this: https://gist.github.com/knobo/adb1bfaa6756161d39b4f2b35fc89d5b
10:33:05
jackdaniel
your snippet doesn't clarify anything to me. to answer the question; optima may be used to do pattern matching from the most specific, if you arrange clauses in correct order (same as with cond really)