> should be guaranteed to bind +FOO+ to a mutable list (1 2 3). Since > MY-LIST isn't proclaimed INLINE, the compiler may not open-code the call.
A minor nit: Although the above is probably very safe (i.e. portable) code, I disagree that the compiler is required not to open-code my-list. On one hand, it would very space inefficient for an implementation to provide inlining for user-defined functions that are not declaimed as inline (unless it was doing some sort of block-compilation). But, OTOH, I don't know of anything in the spec that prohibits some overzealous implementation from doing so.
However, if my-list had been declaimed notinline, then the compiler is definitely constrained by the spec from open-coding it, because the notinline declaration/declamation is one of only 4 delaration specifiers (besides declaration, (greater) safety, and special) that the compiler cannot ignore.
Thus, to make this code completely portable, you could place a (declaim (notinline mylist)) before the defun.
-- Duane Rettig Franz Inc. http://www.franz.com/ (www) 1995 University Ave Suite 275 Berkeley, CA 94704 Phone: (510) 548-3600; FAX: (510) 548-8253 du...@Franz.COM (internet)
Vassil Nikolov <vniko...@poboxes.com> writes: > > [...kidneys...] > I must honestly admit that I don't quite get the point here.
As with my equality paper, it is an intentional issue just how far down identity goes. In a cons, identity is one cons deep. In a list, it's one backbone deep. In an alist, it's two-ply deep.
When you write a user-defined datatype, the compiler can't just be free to lose the identity of the sub-parts becuase it doesn't understand the interrelation. If a compiler dumped me out into a fasl file and then read me back in, it would not suffice to just conjure two new kidneys and say "well, you should have declared them separate constants if you wanted the human beingness of kent to work again after you loaded him". It's better for the language to make it clear that you can't save a complex object at all and expect to get it back unless you write the code to do it because it would be lying to you if it declared otherwise.
I think the reason a lot of you think the language should do this is that you're not used to thinking like a language designer. I don't mean the technical part--there are a lot of sharp technical people. I mean the guilt thing. Language design is a lot about seeing people flail because you gave them enough rope to hang themselves and they did. And I claim that what separates good design from bad design is that good designers not only look for things that are hard in hopes of making them easier, but also they look to where people get in trouble a lot and are willing to take the personal guilt involved in making life more difficult by saying "you won't be allowed to get X for free" because they know that "for free" is a lie and they don't want you to just end in a mire.
Just about anyone could design a more functional set of tools than a language designer can design a language because tools only have to work most of the time and you can kinda shrug and document the places where they don't work. But the importance of being linguistic is that you are the very concrete of the foundation on which all future things will sit, and if you are not designed to be strong, even the tiniest little cracks will add up after a while and their implications will start to be felt in places that are far removed from the places that people are focused on.
I'll give you an example that is off-topic but maybe illustrates what I mean by things felt other places. Just the other day, I was talking to someone about having systems tell you when you make certain dumb little errors. An example might be calling a function with stupid arguments. Not wrong, just stupid. For example: (read-from-string stream :start 2) is a classic. This is completely valid code and it doesn't start reading from position 2. I would allege that it's appropriate to warn about it because the probability is so high that even a mechanical program wouldn't do it that it's worth the warning. But take the following case that Maclisp used to warn about a lot: (member x '(a)) I used to get warnings saying one argument to OR was probably a mistake because it would open code this to (or (eq x 'a)) and it would think it was dumb for me to use OR without at least two things. This warning happened a lot and was well-appreciated for years until macros came into common use, and then it was disastrous. I had code that said: (member x '(a $make-compiler-happy$)) because it was constructed by other code that did `(member x '(,@things $make-compiler-happy$)) and I did not know how many things I would be given. The argument made by the people who wanted the warning about the OR was that the warning was "useful" but the argument made by the others was that "useful or not, it doesn't scale". The language foundation has to be built on things that scale. Similar problems came up about dead code. It's handy to get warnings about code like (cond (foo x) (t y) (bar z)) if no macros are involved, but if a macro is involved, and if the compiler is deadset on issuing a warning, you're in a real problem and you have to do weird things like: (cond (foo x) (*lisp-wont-be-told-until-after-compilation-that-this-is-t* y) (bar z)) And even then, it's probably going to result in slower code.
> (defun make-thing () > "Return an uninterned object---a fresh vector of bignums." > (make-array 17 :initial-value (1+ most-positive-fixnum)))
> (1) DEFCONSTANT where the value is not interned in any way, e.g.
> (defconstant =foo= (make-thing) "some object")
(Confess: This whole discussion was just an excuse to slip in some subliminal references to =...= for constants, wasn't it? :-)
> The value returned by another evaluation of the same form that > initialises =FOO= would not be EQL to =FOO= and (EQL =FOO= =FOO=) > may or may not be true depending on whether =FOO= is inlined. > No registration of any kind here.
> *but* (MAKE-THING) is evaluated only once for _all_ files that > refer to =FOO=, and evaluation may take place as early as compile > time: with =FOO-AS-SYMBOL-MACRO=, evaluation will take place at > run time, and with
> evaluation will take place at load time (and not once for _all_ > files but once for _each_ file).
I don't get the thing with the files. Files are an artificial concept that you shouldn't introduce unless you absolutely have to. If you want to talk about files with respect to externalization, there may be no alternative. But "evaluation" is not about externalization, and indeed evaluation may be insensitive to what file is involved (for nested files, for cases where no file is involved, etc.).
> (2) DEFCONSTANT where the value is interned in some way, e.g.
> (defconstant =bar= 'baz "an interned symbol")
> EQL identity is guaranteed not by virtue of what DEFCONSTANT does > but by virtue of the properties of the value given to the constant > variable: (EQL =BAR= =BAR=) and (EQL =BAR= 'BAZ) will both be true > because this is how interned symbols work, and it doesn't matter > if =BAR= is inlined or not. The reference is not registered, > the value is.
> (By the way, this reminds me of the concept of otherwise accessible > parts.)
I just knew someone was going to raise that. It seems like it should be related, but it's not. Indeed, just the opposite. The whole PROBLEM is that the parts of a constant ARE accessible. Why? Because the whole point of a constant is to use it in code. If you didn't use it, you wouldn't need it. And having used it, you can't know what the system has done with it--unless you forbid the system from doing useful things, which seems silly.
> (3) A constant reference where the value is not interned in any way: > EQL identity is guaranteed only via the same reference but not between > the constant reference and the value produced by another evaluation > of the initialisation form. The reference is registered (terminology?), > the value isn't.
I'm not sure what it means to be the same reference. In (let* ((x +quux+) (y x)) (eql x y)) is there one reference or two?
> (4) A constant reference where the value is interned: EQL identity > is guaranteed in all cases, i.e. one can obtain the same (EQL) object > not only by another occurrence of the same constant reference but > also by another evaluation of the initialisation form (or its > equivalent, in the same sense that 'BAZ and (INTERN "BAZ") are > equivalent (ceteris paribus: same package, same read case)).
I guess what I'm saying is that similarity is about interning "as needed", and this is closest to correct. For numbers, interning isn't needed (though is often practiced for storage reasons) because there are no comparison operators that can tell the difference between numbers other than EQ which you are encouraged never to use, and there are no mutators on numbers much though Drew McDermott used to lament the passing of "bignums you could rplaca and rplacd" like you used to have in Maclisp. For packages, interning is needed because there are mutators on packages. For some structures, mutating is an issue and for some it's not, and so appropriate MAKE-LOAD-FORM definitions have to be written.
> I wrote just `constants' where I should have written `constant > variables.' Correct me if I am wrong, but inlining may happen no matter > if the initialisation form in DEFCONSTANT is QUOTE or LOAD-TIME-VALUE.
I'm not positive I know the answer or that there is an answer.
I can see differing interpretations. It seems to me the whole point of DEFCONSTANT is to say "the compiler may aggressively view the result of this computation" and the whole point of saying LOAD-TIME-VALUE it to say "the compiler may not aggressively view the result of this computation". Do they cancel? Is the entire form evaluated as if by EVAL and is "load-time" for the "EVAL" the same as compile-time? I don't know if I know the answer. I know I've spent so long replying to this that I'm not going to spend more time researching it today.
> > > Another thing that might be useful would be control over the > > > mutability of the object that is the value of a constant (similar > > > to what is there for LOAD-TIME-VALUE).
> > I don't know what this is about. LOAD-TIME-VALUE seems entirely > > powerful enough.
>>>>> "Erik" == Erik Naggum <e...@naggum.no> writes:
Erik> * chu...@best.com (Chuck Fry) Erik> | Modern Common Lisp compilers allow me to tune the critical parts of my Erik> | code to within a few percent of C code, but without the pain of using a Erik> | fragile, brittle quasi-portable assembly language.
Erik> just for the heck of it: I have tuned a _very_ CPU-heavy function I wrote Erik> in Common Lisp over a year ago so it went from the unsatisfactory 623 µs Erik> per call to the very pleasant 4.7 µs per call.
Would it be possible to provide the before and after versions of the code?
In article <4niubflwhf....@rtp.ericsson.se>, Raymond Toy <t...@rtp.ericsson.se> writes:
>>>>>> "Erik" == Erik Naggum <e...@naggum.no> writes: > Erik> * chu...@best.com (Chuck Fry) > Erik> | Modern Common Lisp compilers allow me to tune the critical parts of my > Erik> | code to within a few percent of C code, but without the pain of using a > Erik> | fragile, brittle quasi-portable assembly language. > Erik> just for the heck of it: I have tuned a _very_ CPU-heavy function I wrote > Erik> in Common Lisp over a year ago so it went from the unsatisfactory 623 µs > Erik> per call to the very pleasant 4.7 µs per call. > Would it be possible to provide the before and after versions of the > code? > I think it would be very instructive. > Ray
Actually, several steps in the evolution might be even more interesting
* h...@inferno.nirvananet (Hartmann Schaffer) | Actually, several steps in the evolution might be even more interesting
OK, I'll do the steps thing. at issue was hacking up and printing a time representation. the naïve solution is to use a bignum of seconds since some human-inspired epoch, use FORMAT with ~D to print it. however, I also needed proper timezone support (CL's support is suitable only if you deal with times in a single timezone), and milliseconds (since a second is a really long time to modern computers, and even milliseconds are). the zone was represented as the number of hours west of Greenwich.
the time representation is now split up into day, time, and milliseconds. the zone is changed to seconds eas of Greenwich. day 0 is 2000-03-01, because that's when a new 400-year leap year period starts, which means that the leap day is at the end of the four years, the centennium, and the quatercentennium, and thus no expensive computations are needed to check for leap years. however, the main culprit was division. it is an expensive operation, table lookup not, so I precomputed tables for the 146097 days of a quatercentennium and the 86400 seconds of a day, and did a nifty data representation hack so the values fit in a single fixnum.
the full time representation was changed from a class to a structure, and proper declarations meant that the access functions were inlined and the type (fixnum) propagated properly.
time comparison functions now compared three fixnums instead of bignums and a fixnum (milliseconds) and that meant the timezone tables (extracted from the Unix timezone database that the C library uses (but also gives you exactly one handle on)), were searched much faster. in addition, the interval of the timezone was made available to the caller upon demand (it affects the length of a local day, which can be 23, 24, or 25 hours!) and also cached, since most times decoded were in the same timezone. the time zone adjustment function also did simple addition and subtraction instead of new divisions into day and time.
what really made a difference once I had figured out how to store the values in a fixnum (I'll leave that as an exercise for the reader -- since it's so far from obvious how to do it, some people will get a real kick out of how simple it is, and I don't want to take that kind of joy away form anyone), was to pass a preallocated vector for the decoding functions to store its values into instead of returning them as multiple values.
finally, printing turned out to be very division-intensive, too, so I precomputed a pair of tables of high and low digits for 100 numbers. streams were also very expensive, so I deposited characters directly into a preallocated string and returned a copy or wrote it out (depending on whether the stream argument was NIL or a stream, like FORMAT). centuries were easy to change into numbers in the 16 to 99 range instead of 1600 to 9900.
(granted, I have built myself a system with a serious Y10K problem, but I'll print a warning in the year 9900 if it makes anyone less worried. rumor has it that Y1K brought us the Dark Ages because it took 400 years to update all the software to four instead of three digits in the year.)
the only real problem I had with tuning this stuff was that a 400 MHz CPU is damn hard to get useful statistics from every 10 ms. it manages to do a tremendous lot of work in 10 ms, so I had to let profiling run for many minutes to collect useful data as I got closer to the optimum.
> check for leap years. however, the main culprit was division. it is an > expensive operation, table lookup not, so I precomputed tables for the > 146097 days of a quatercentennium and the 86400 seconds of a day, and did > a nifty data representation hack so the values fit in a single fixnum.
With "the values" you mean the human readable form of the (day, millisec, timezone) triplet?
..
> what really made a difference once I had figured out how to store the > values in a fixnum (I'll leave that as an exercise for the reader -- > since it's so far from obvious how to do it, some people will get a real > kick out of how simple it is, and I don't want to take that kind of joy
So (year,month,day,hour,minute,second) in a fixnum, right?
..
> finally, printing turned out to be very division-intensive, too, so I
*nod*nod*
> the only real problem I had with tuning this stuff was that a 400 MHz CPU > is damn hard to get useful statistics from every 10 ms. it manages to do > a tremendous lot of work in 10 ms, so I had to let profiling run for many > minutes to collect useful data as I got closer to the optimum.
Aha. Is it not possible to use the cycle-counter on modern x86's to check this. You would have to insert get-the-count instructions here and there, but it gives you a resolution of 1 clock tick. IIRC
Groetjes, Peter
-- It's logic Jim, but not as we know it. | pvane...@debian.org for pleasure, "God, root, what is difference?",Pitr | pvane...@inthan.be for more pleasure!
* pvane...@mail.inthan.be (Peter Van Eynde) | With "the values" you mean the human readable form of the (day, millisec, | timezone) triplet?
no, the individual (day month year) and (second minute hour) triples.
| So (year,month,day,hour,minute,second) in a fixnum, right?
no. keep trying. :)
| Aha. Is it not possible to use the cycle-counter on modern x86's to | check this. You would have to insert get-the-count instructions here and | there, but it gives you a resolution of 1 clock tick. IIRC
yes, this is possible, but as far as I can see, Allegro CL does not support this mode of operation. I think it's a little too much to ask, too, but if I can get over the _disgusting_ machine language in the Intel CPU's, I might play with this one day...
In article <sfwzp4s2cqk....@world.std.com>, Kent M Pitman <pit...@world.std.com> wrote: (...)
> As with my equality paper, it is an intentional issue just how far down > identity goes.
(...) ;can one get the same object back?
I knew that this issue is going to teach me more than just about constants and constantness. I can see more clearly now that my mindset about objects goes like this: the identity of an object lasts only as long as it lives in core, i.e. there is a `live' reference to it. Externalising and internalising in the general case means losing its identity. There is no _general_ way to prevent this: achieving this prevention can only be considered on a case per case basis.
(I am not saying that my mindset is right or wrong, just want to grasp it better. And it does need more refinement.)
(...) ;on language design
You are right that I don't think like a language designer, and I should try to imagine myself in a language designer's shoes, as it were, more often. I guess I am now rather irresponsibly testing how far the cracks would open...
As an aside, isn't one of the good things about Lisp that with it one plays with a _language_, while with C one plays with a _machine_ (and with C++ one---well, is engaged in non-playful activities with a machine).
> I'll give you an example that is off-topic
(...) ;an instructive example so what if it might be off-topic
> I had code that said: > (member x '(a $make-compiler-happy$)) > because it was constructed by other code that did > `(member x '(,@things $make-compiler-happy$)) > and I did not know how many things I would be given.
(...)
I think that this is at least one of the reasons why it is important to distinguish between program writing time and compile time.
> (Confess: This whole discussion was just an excuse to slip in some > subliminal references to =...= for constants, wasn't it? :-)
:-)
You got me!
<annoying-Latin-mode-again> Next I'll be putting into my signature `Ceterum, censeo, names of constant variables should have equal signs around them.' </annoying-Latin-mode-again>
(...) ;number of times a DEFCONSTANT initialisation form is evaluated ; vs. number of times a LOAD-TIME-VALUE form in a symbol macro ; expansion is evaluated
> I don't get the thing with the files. Files are an artificial concept > that you shouldn't introduce unless you absolutely have to. If you want > to talk about files with respect to externalization, there may be > no alternative. But "evaluation" is not about externalization, and indeed > evaluation may be insensitive to what file is involved (for > nested files, for cases where no file is involved, etc.).
Trying to get this right: `artificial' in the sense that if a program consists of several files, an equivalent program can be constructed from combining all files into one? But doesn't such equivalence have only theoretical value?
I may be missing the point again but the concept of files has a clear presence via LOAD and COMPILE-FILE. My concern here is related not to externalisation but to side effects (including functions such as RANDOM that return different values on each invocation), and I wanted to highlight differences I can see between DEFCONSTANT and DEFINE-SYMBOL-MACRO (straighforward use of the latter in particular, imitating #define).
As far as I can see,
(defconstant =foo= '(a b c) "a list")
and
(define-symbol-macro =foo= '(a b c))
do the same job; but consider these two scenarios (untested, sorry!):
(i) DEFCONSTANT:
;;; setting the stage: (defparameter *counter* 0 "to be incremented by one") (defun counter () (list 'counter (incf *counter*))) (defconstant =foo-const= (load-time-value (counter) t) "a list containing an integer")
File one: (format t "~&one/1: ~S" =foo-const=) (format t "~&one/2: ~S" =foo-const=)
File two: (format t "~&two/1: ~S" =foo-const=) (format t "~&two/2: ~S" =foo-const=)
Whether constant variables are inlined or not, loading these files one after the other would print
> > (2) DEFCONSTANT where the value is interned in some way, e.g.
> > (defconstant =bar= 'baz "an interned symbol")
> > EQL identity is guaranteed not by virtue of what DEFCONSTANT does > > but by virtue of the properties of the value given to the constant > > variable: (EQL =BAR= =BAR=) and (EQL =BAR= 'BAZ) will both be true > > because this is how interned symbols work, and it doesn't matter > > if =BAR= is inlined or not. The reference is not registered, > > the value is.
> > (By the way, this reminds me of the concept of otherwise accessible > > parts.)
> I just knew someone was going to raise that. It seems like it should > be related, but it's not. Indeed, just the opposite. The whole PROBLEM
Problem?
> is that the parts of a constant ARE accessible. Why? Because the whole
Yes, they are---this is what I wrote---`otherwise accessible,' not `otherwise inaccessible' (was it too self-assured of me to coin the opposite of the existing phrase?).
> point of a constant is to use it in code. If you didn't use it, you > wouldn't need it. And having used it, you can't know what the system > has done with it--unless you forbid the system from doing useful things, > which seems silly.
God forbid that I should forbid anything or anyone from doing useful things... (not that I don't do silly things from time to time).
> > (3) A constant reference where the value is not interned in any way: > > EQL identity is guaranteed only via the same reference but not between > > the constant reference and the value produced by another evaluation > > of the initialisation form. The reference is registered (terminology?), > > the value isn't.
> I'm not sure what it means to be the same reference. > In (let* ((x +quux+) (y x)) (eql x y)) is there one reference or two?
^^^^^^ ^ ^ ^ Four occurrences of the same reference which has been propagated from +QUUX+ to X and then via X to Y.
Yes, there's some ambiguity in `reference.' If we agree to visualise references as arrows, sometimes `reference' means the start of the arrow and sometimes the end of the arrow, I think. So in the above LET* form there are three arrows (one for +QUUX+, one for X, one for Y), with X's being used twice, and all of which end at the same object.
(...)
> > Correct me if I am wrong, but inlining may happen no matter > > if the initialisation form in DEFCONSTANT is QUOTE or LOAD-TIME-VALUE.
> I'm not positive I know the answer or that there is an answer. > I can see differing interpretations. (...) > I know I've spent so long replying to this that > I'm not going to spend more time researching it today.
Yes, perhaps in the spirit of lazy evaluation this question is better left until someone really *must* know, and then they will have a specific case in hand which might make arguing one way or the other easier.
> > > > Another thing that might be useful would be control over the > > > > mutability of the object that is the value of a constant (similar > > > > to what is there for LOAD-TIME-VALUE).
> > > I don't know what this is about. LOAD-TIME-VALUE seems entirely > > > powerful enough.
> > Once again, please read `constant variable' for `constant' in my > > sentence. A constant variable is always immutable. (There is > > no `read-only-p' parameter to DEFCONSTANT.)
> It's not obvious to me what it would mean. Suppose I have a non-read-only > constant and I write it to a file, then I modify it, then I write it to > another file. What is the world like when I load both files in the target > environment? The whole point of a thing you can "aggressively reason about" > is that "you know its contents". It doesn't make sense to say you can know > its identity in advance because it has no pointer identity until runtime. > Only its parts matter, so to say that you're going to sacrifice the parts > for the iddentity so that you can modify it but you can't trust the contents > of that modification seems very odd.
I admit I wasn't thinking about externalising and then internalising with modifications in between, just about in-core operations. It's best for me to retract my idea at least until I know better what I am talking about.
(...)
> > (And `adequately' here also means access in O(1); implementing > > somehow a constant reference on top of a `private' global variable > > does not ensure that because of the possibility of deep binding.)
> (defun lexical-cell (x) > (or (get x 'lexical-cell) > (setf (get x 'lexical-cell) (cons x +lexical-unbound+))))
CONS in order to ensure that the first argument to OR is false iff no value has been given yet, right? (And the choice of the first argument to CONS is mainly for convenience of debugging and inspecting?)
-- Barry Margolin, bar...@bbnplanet.com GTE Internetworking, Powered by BBN, Burlington, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Vassil Nikolov <vniko...@poboxes.com> writes: > You are right that I don't think like a language designer, and I > should try to imagine myself in a language designer's shoes, as it > were, more often. I guess I am now rather irresponsibly testing > how far the cracks would open...
Oh, I don't know if I'd say "irresponsibly". Thought experiments like this are what this newsgroup is for. And, btw, I'm not saying I'm always right. A lot of people are beating me up on this one, and for all I know they might be right. But I'm not going to change my mind just because I'm outvoted. I'm sticking with my opinion until I see a reason to change my mind. As I hope others will.
> Yes, they are---this is what I wrote---`otherwise accessible,' not > `otherwise inaccessible' (was it too self-assured of me to coin the > opposite of the existing phrase?).
Uh, just too obscure for me to notice, I think. :-)
> Yes, there's some ambiguity in `reference.'
Incidentally, this ambiguity hit the Scheme community when there was a question of whether: (let ((x (+ y 3))) x) has (+ y 3) in a "tail recursive" position. I think that's the funny case, anyway. The rule of present is, I think, that this is only optionally seen as "tail recursive". In a future standard, the Scheme authors plan to clarify this. But variables are funny things...
> I admit I wasn't thinking about externalising and then internalising > with modifications in between, just about in-core operations. It's > best for me to retract my idea at least until I know better what I am > talking about.
Oh, darn. And here I just thought if I forced people to repeat this to me another 20 or 30 times I'd eventually understand why they were so excited about it...
> > (defun lexical-cell (x) > > (or (get x 'lexical-cell) > > (setf (get x 'lexical-cell) (cons x +lexical-unbound+))))
> CONS in order to ensure that the first argument to OR is false iff > no value has been given yet, right?
Right. And because CONS is the cheapest way of making a "cell" in most implementations. In fact, only a half-cons is needed, but most implementations have no such datatype--certainly the standard doesn't.
> (And the choice of the first > argument to CONS is mainly for convenience of debugging and inspecting?)
In article <sfw4smyw319....@world.std.com> Kent M Pitman writes:
Incidentally, this ambiguity hit the Scheme community when there was a question of whether: (let ((x (+ y 3))) x) has (+ y 3) in a "tail recursive" position. I think that's the funny case, anyway. The rule of present is, I think, that this is only optionally seen as "tail recursive". In a future standard, the Scheme authors plan to clarify this. But variables are funny things...
R5RS has this:
In the following example the only tail call is the call to f. None of the calls to g or h are tail calls. The reference to x is in a tail context, but it is not a call and thus is not a tail call.
Note: Implementations are allowed, but not required, to recognize that some non-tail calls, such as the call to h above, can be evaluated as though the were tail calls. (...)
So EQL is unspecified in the former case and false in the latter; the real difference I can see between these two examples is that one can destructively modify the value coming from the symbol macro.
Vassil Nikolov <vniko...@poboxes.com> www.poboxes.com/vnikolov (You may want to cc your posting to me if I _have_ to see it.) LEGEMANVALEMFVTVTVM (Ancient Roman programmers' adage.)
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
In article <sfw4smyw319....@world.std.com>, Kent M Pitman <pit...@world.std.com> wrote:
> Vassil Nikolov <vniko...@poboxes.com> writes: (...) > But I'm not going to change my mind just because > I'm outvoted. I'm sticking with my opinion until I see a reason to > change my mind. As I hope others will.
One of my high-school teachers in literature used to say, when there was disagreement among the class e.g. whether an author really meant this and this or that and that, `shall we vote on it?'
Not to mention that ill fated attempt in one of the states of the USA to vote on a formula implying a rather poor approximation of pi.
> > Yes, they are---this is what I wrote---`otherwise accessible,' not > > `otherwise inaccessible' (was it too self-assured of me to coin the > > opposite of the existing phrase?).
> Uh, just too obscure for me to notice, I think. :-)
In any case, I should be more careful with unusual phrases that are likely to be taken for their well-known opposite.
(...)
> But variables are funny things...
They make our lives more interesting. And I recall that old fortune cookie, `Variables won't, constants aren't.'
> > I admit I wasn't thinking about externalising and then internalising > > with modifications in between, just about in-core operations. It's > > best for me to retract my idea at least until I know better what I am > > talking about.
> Oh, darn. And here I just thought if I forced people to repeat this > to me another 20 or 30 times I'd eventually understand why they were > so excited about it...
I am excited about it essentially because I hope this can help me understant what an object __really__ is. It's a distant goal, and I want to talk again about the issue in public after I have made some more progress in private.
(...)
> And because CONS is the cheapest way of making a "cell" in most > implementations. In fact, only a half-cons is needed, but most > implementations have no such datatype--certainly the standard doesn't.
I have mentioned this a couple of times already (sorry for repeating myself): how about a zero-dimensional array as an idiom for a half-cons (i.e. a singleton reference)? Of course, it is rather unlikely that in any given implementation making and/or garbage collecting a zero-dimensional array would be cheaper than the same operations on a cons cell, but this would save the comment saying something like, `only the car of this cons is really used.'
(...)
Thanks for the followup clarifications about the example.
(...) ;using LOAD-TIME-VALUE to get a `lock' on a reference ; (not in the usual sense of `lock' for mutual exclusion, ; but in the same sense as a radar locks on a target--- ; sorry for the military metaphor)
> I think it's a nice trick, so if it isn't obvious to you what it's > doing, it's worth a second look.
It is indeed. In fact, I believe it deserves to appear as a textbook exercise so students have the satisfaction of discovering it themselves. And it also show a not very obvious benefit from LOAD-TIME-VALUE.
> > Happy Easter!
> You, too!
Thanks! I'll save this for a week from now (this year Eastern Orthodoc Easter is a week later than Easter of the Western Churches).
Vassil Nikolov <vniko...@poboxes.com> www.poboxes.com/vnikolov (You may want to cc your posting to me if I _have_ to see it.) LEGEMANVALEMFVTVTVM (Ancient Roman programmers' adage.)
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Where in the spec does it say that? I believe the compiler can inline =FOO=, replacing it with its value, which should be the list that =FOO= is bound to. Section 3.2.2.3 of the CLHS says, "A reference to a constant variable in source code is equivalent to a reference to a literal object that is the value of the constant variable." It doesn't say that it's equivalent to a reference to a listeral object that's *similar* to the value.
-- Barry Margolin, bar...@bbnplanet.com GTE Internetworking, Powered by BBN, Burlington, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
rtha...@leonce.mathematik.uni-freiburg.de (Rolf-Thomas Happe) writes: > In article <sfw4smyw319....@world.std.com> Kent M Pitman writes: > Incidentally, this ambiguity hit the Scheme community when there was > a question of whether: > (let ((x (+ y 3))) > x) > has (+ y 3) in a "tail recursive" position. I think that's the funny > case, anyway. The rule of present is, I think, that this is only > optionally seen as "tail recursive". In a future standard, the Scheme > authors plan to clarify this. But variables are funny things...
> R5RS has this:
> In the following example the only tail call is the call to f. None > of the calls to g or h are tail calls. The reference to x is in a > tail context, but it is not a call and thus is not a tail call.
> Note: Implementations are allowed, but not required, to recognize > that some non-tail calls, such as the call to h above, can be > evaluated as though the were tail calls. (...)
Yes. If you look earlier in the document you'll see I'm among the "authors" (more like a design committee, with all the argumentation and disarray that committeeness sometimes implies) of this document you're referring me to. It was just late and I didn't want to bother looking it up.
My point was not about what Scheme does now, but rather that we discussed how it should be defined and it was, as I recall, decided that without making it formal exactly what was to be detected, it wasn't the right time to define that (h) in the above is a tail call. But that might change in the future. Various people are getting psyched to make the whole business of storage usage in these situations more formal.
And the more general point was to underscore that this matter of "variables" and "reference" and "code substitution" is a messy gray area that affects not just this discussion of defconstant but other things as well.
Vassil Nikolov <vniko...@poboxes.com> writes: > how about a zero-dimensional array as an idiom for a half-cons > (i.e. a singleton reference)?
As a rule, arrays are higher overhead to access than conses. And they have to have header info that says what their dimension size is, so that would use up the space you saved by going into array--maybe even more. I don't know how much overhead arrays have on them in typical implementations but they do use more storage than just the element memory itself, I'm pretty sure.
It might help a little if you knew the 0d array was also simple.(I never saw a displaced or adjustable 0d array, but I think it's possible in principle. :-)
Maclisp had the HUNK datatype which was the right thing. It was a generalized cons that had however many parts you wanted. A 1-element hunk was still of type HUNK2 (represented identically to CONS, but in a different allocation space) but had a filler in one of its slots that said "nothing here". I was sad hunks went away, though they really were a kind of hack ... I guess the main reason they went away was that they had been co-opted as a low-level implementation substrate for implementing class-like things in pre-class-system days, and when a real class data structure came along, it wasn't as needed. I suppose you could use a structure with only one slot, but since it would have a header saying the type of the structure, it would take up the same space as a CONS anyway. Just can't quite win.
Kent M Pitman <pit...@world.std.com> wrote: +--------------- | > Yes, there's some ambiguity in `reference.' | | Incidentally, this ambiguity hit the Scheme community when there was | a question of whether: | (let ((x (+ y 3))) | x) | has (+ y 3) in a "tail recursive" position. I think that's the funny | case, anyway. +---------------
Perhaps you are thinking of some other funny case? This one seems pretty clear (even without resorting to R5RS). Since (even in R4RS) "let" is a "derived expression", its defining semantics are given in terms of a procedure call of its body, i.e., translating your example:
((lambda (x) x) (+ y 3))
Now that being the case, and given that Scheme is a call-by-value variant of the lambda calculus, if I understand these things correctly the "(+ y 3)" is *not* in a tail position, since it must be evaluated *before* the call to the lambda.
The lambda itself is not in a tail position, either, for the same reasons. But the *body* of the lambda ("x", in this case) is...
Hmmm... I see here that R5RS *allows* the beta-reduction to "(+ y 3)" [which would convert it to a tail call of "+"], in section "3.5 Proper Tail Recursion" [just after the example Darius(?) quoted which contained a (let ((x (h))) x) as one branch of an "if"], where it says:
Note: Implementations are allowed, but not required, to recognize that some non-tail calls, such as the call to "h" above can be evaluated as though they were tail calls. In the example above, the "let" expression could be compiled as a tail call to "h".
So it's only "in a tail position" if your compiler is smart enough to *prove* that making it so won't break the semantics...
-Rob
----- Rob Warnock, 8L-855 r...@sgi.com Applied Networking http://reality.sgi.com/rpw3/ Silicon Graphics, Inc. Phone: 650-933-1673 2011 N. Shoreline Blvd. FAX: 650-964-0811 Mountain View, CA 94043 PP-ASEL-IA
Vassil Nikolov <vniko...@poboxes.com> wrote: +--------------- | how about a zero-dimensional array as an idiom for a half-cons | (i.e. a singleton reference)? +---------------
Several Scheme implementations have such a notion for a half-cons, conventially called a "box":
> > how about a zero-dimensional array as an idiom for a half-cons > > (i.e. a singleton reference)?
> As a rule, arrays are higher overhead to access than conses. And they > have to have header info that says what their dimension size is, so > that would use up the space you saved by going into array--maybe even > more. I don't know how much overhead arrays have on them in typical > implementations but they do use more storage than just the element > memory itself, I'm pretty sure.
Oh, yes. Of course it is highly implementation dependent, but my `generalised implementation-independent' estimate is 8 bytes (which is useful only to maintain some _rough_ mental idea of storage costs).
I hope I mentioned it that I was aware of higher costs---the reason why I still put forward 0d arrays has to do with expressing intent, see below.
(In fact, assuming 64 bits of header and, in a 64-bit architecture, 64 bits per reference, a simple array with room for a single element would occupy as much storage as a cons cell. But this is just hypothetical.)
> It might help a little if you knew the 0d array was also simple.(I > never saw a displaced or adjustable 0d array, but I think it's > possible in principle. :-)
It ought to be possible to have a 0d displaced array. But adjustable? Don't ask, don't tell...
> Maclisp had the HUNK datatype which was the right thing. It was a > generalized cons that had however many parts you wanted. A 1-element > hunk was still of type HUNK2 (represented identically to CONS, but in > a different allocation space) but had a filler in one of its slots that > said "nothing here". I was sad hunks went away, though they really > were a kind of hack ... I guess the main reason they went away was that
I had known about Maclisp's hunks only from comp.lang.lisp. They do look like what I want but I know I should not be holding my breath for their re-introduction into the language.
> they had been co-opted as a low-level implementation substrate for > implementing class-like things in pre-class-system days, and when a > real class data structure came along, it wasn't as needed. I suppose > you could use a structure with only one slot, but since it would have > a header saying the type of the structure, it would take up the same > space as a CONS anyway. Just can't quite win.
In theory at least, an implementation could have a specific tag for a singleton reference so that the reference itself does take half the space for a cons cell. But even though it could, I don't expect that it would, it being too much trouble for something that's rarely needed.
But, before worrying about storage, I worry about a clear expression of my intent to use something as a singleton reference.
(1) Using a cons is most efficient but is one of those `cancer of the semicolon' cases:
(let ((ref (cons foo nil))) ;the cdr will not be used ...) ^^^^^^^^^^^^^^^^^^^^^^^^^
(2) Using a structure makes for a program where adding a second slot is an easy change to the program: a structure with just one slot still sort of implies that a second slot might appear some day, and I don't want that. For the same reason, I want a _zero_ dimensional array, not a vector of length 1: (AREF REF) means there is just this one, period, while (AREF REF 0) again sort of implies that one day we might see (AREF REF 1) etc.
(3) Of course I could say
(defstruct ref obj) ;thou shalt have just this slot
but on the other hand sometimes I (perhaps others too) prefer idioms to Doing the Right Thing by introducing abstractions for each and every purpose and thus cluttering the program with defining forms and the concept space with datatypes, accessors, etc. (For the same reason I am not very keen on wrapping calls to CONS and FIRST in calls to MAKE-REF and REF.)
Anyway, this exercise is not worth more than the proverbial two cents since even if `efficient singleton references' makes it to a wish list it would have very nice(1) priority...
I also remember the case of Algol-68, which among other things tried to Get references Right, I believe.
Vassil Nikolov <vniko...@poboxes.com> www.poboxes.com/vnikolov (You may want to cc your posting to me if I _have_ to see it.) LEGEMANVALEMFVTVTVM (Ancient Roman programmers' adage.)
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
In article <7e6rsp$k...@fido.engr.sgi.com>, r...@rigden.engr.sgi.com (Rob Warnock) wrote:
> Vassil Nikolov <vniko...@poboxes.com> wrote: > +--------------- > | how about a zero-dimensional array as an idiom for a half-cons > | (i.e. a singleton reference)? > +---------------
> Several Scheme implementations have such a notion for a half-cons, > conventially called a "box":
(...)
Thanks, this is interesting to know. I am afraid I can't find the time to follow Scheme developments, so it is good that I can catch at least some pieces from comp.lang.lisp.
Are boxes as efficient as cons cells in terms of speed of access and memory use? (By the latter I mean, does a box take up half the space for a cons?)
> p.s. FWIW, MzScheme provides the following > printer & reader syntax for boxes:
> > foo > #&24
(...)
But I suspect that reading this back would produce a fresh box--- is that so? If yes, this may or may not be what I want, and we have hit the externalisation issue again...
Vassil Nikolov <vniko...@poboxes.com> www.poboxes.com/vnikolov (You may want to cc your posting to me if I _have_ to see it.) LEGEMANVALEMFVTVTVM (Ancient Roman programmers' adage.)
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
> Where in the spec does it say that? I believe the compiler can inline > =FOO=, replacing it with its value, which should be the list that =FOO= is > bound to. Section 3.2.2.3 of the CLHS says, "A reference to a constant > variable in source code is equivalent to a reference to a literal object > that is the value of the constant variable." It doesn't say that it's > equivalent to a reference to a listeral object that's *similar* to the > value.
First, the relevant item from 3.2.2.3 Semantic Constraints reads in full (with the first sentence included):
Constant variables defined in the compilation environment must have a similar value at run time. A reference to a constant variable in source code is equivalent to a reference to a literal object that is the value of the constant variable.
so similarity is already mentioned here.
Second:
3.2.4 Literal Objects in Compiled Files
The functions eval and compile are required to ensure that literal objects referenced within the resulting interpreted or compiled code objects are the same as the corresponding objects in the source code. compile-file, on the other hand, must produce a compiled file that, when loaded with load, constructs the objects defined by the source code and produces references to them.
In the case of compile-file, objects constructed by load of the compiled file cannot be spoken of as being the same as the objects constructed at compile time, because the compiled file may be loaded into a different Lisp image than the one in which it was compiled. This section defines the concept of similarity which relates objects in the evaluation environment to the corresponding objects in the run-time environment.
The constraints on literal objects described in this section apply only to compile-file; eval and compile do not copy or coalesce constants.
(By the way, it was easy to find these as the links to them still show up as recently visited in my browser.)
I find the above to mean that the file compiler _may_ inline the value of a constant variable: it treats it like it treats a literal object (3.2.2.3), and for that only similarity, and not necessarily eqlness, must be observed (3.2.4, 2nd paragraph).
To make sure there's no misunderstanding, for me
(EQL =FOO= =FOO=) may return T or NIL
is shorthand for:
if a file has, say, (DEFUN FOO1 () =FOO=), and another file has, say, (DEFUN FOO2 () =FOO=), then (EQL (FOO1) (FOO2)) may return T or NIL.
(While (EQL =FOO= =FOO=) does not necessarily imply programmer silliness if it is seen by the compiler (since one or both foo's may come from macro expansion), I would find it hard to argue that the latter form may return NIL as it can occur but within a single file.)
So if (EQL (FOO1) (FOO2)) => NIL, one might be right to say that the implementation worked in a counter-intuitive, unexpected, or harmful way (I would disagree but I wouldn't argue about that here), but one would *not* be right to say the implementation broke the rules.
Once again, my summary of the issue (which maybe deserves attention if and when the standard is reviewed) is: like DEFINE-SYMBOL-MACRO, DEFCONSTANT does not provide a constant reference (non-inlinable) to an object. (DEFCONSTANT differs from DEFINE-SYMBOL-MACRO with respect to other things: when and how many times the value form is evaluated, and also with respect to the possibility of the same symbol appearing in a binding form.)
Vassil Nikolov <vniko...@poboxes.com> www.poboxes.com/vnikolov (You may want to cc your posting to me if I _have_ to see it.) LEGEMANVALEMFVTVTVM (Ancient Roman programmers' adage.)
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Vassil Nikolov <vniko...@poboxes.com> wrote: +--------------- | r...@rigden.engr.sgi.com (Rob Warnock) wrote: | > +--------------- | > | ...idiom for a half-cons (i.e. a singleton reference)? | > +--------------- | > | > Several Scheme implementations have such a notion for a half-cons, | > conventially called a "box": ... | Are boxes as efficient as cons cells in terms of speed of access and | memory use? (By the latter I mean, does a box take up half the space | for a cons?) +---------------
It all depends on the implementation, I'd guess. In MzScheme a box is an instance of "Scheme_Small_Object", which is a type field [a short, but most compilers will force that to a PSV] and a pointer-sized value (PSV). A cons is an instance of "Scheme_Object", which is a type field and two PSVs. So for MzScheme, a box is 2/3 (or maybe 3/5) the size of a cons.
In an implementation I've been working on [play project], the same is true: a box is 2/3 the size of a cons.
In article <7e9pec$64...@nnrp1.dejanews.com>, Vassil Nikolov <vniko...@poboxes.com> wrote:
>In theory at least, an implementation could have a specific tag for >a singleton reference so that the reference itself does take half the >space for a cons cell. But even though it could, I don't expect that >it would, it being too much trouble for something that's rarely needed.
-- Barry Margolin, bar...@bbnplanet.com GTE Internetworking, Powered by BBN, Burlington, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Erik Naggum <e...@naggum.no> writes: > * pvane...@mail.inthan.be (Peter Van Eynde) > | With "the values" you mean the human readable form of the (day, millisec, > | timezone) triplet?
> no, the individual (day month year) and (second minute hour) triples.
> | So (year,month,day,hour,minute,second) in a fixnum, right?
In article <JF4O2.264$kM2.40098@burlma1-snr2>, Barry Margolin <bar...@bbnplanet.com> wrote:
> In article <7e9pec$64...@nnrp1.dejanews.com>, > Vassil Nikolov <vniko...@poboxes.com> wrote: > >In theory at least, an implementation could have a specific tag for > >a singleton reference so that the reference itself does take half the > >space for a cons cell. But even though it could, I don't expect that > >it would, it being too much trouble for something that's rarely needed.
Unfortunately my knowledge of Lisp Machines is rather limited, so I can't say. I hope someone else would answer.
Assuming Lisp Machine locatives are singleton references, I'm also curious to know what were the reasons why they didn't make it into Common Lisp (to avoid complexity? to avoid expensive implementation on stock hardware? ...)
Vassil Nikolov <vniko...@poboxes.com> www.poboxes.com/vnikolov (You may want to cc your posting to me if I _have_ to see it.) LEGEMANVALEMFVTVTVM (Ancient Roman programmers' adage.)
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own