Hi, I don't have a clue here. I understand that Lisp is not a base-sensitive language; it turns everything into base 10. When I enter an integer as #xFF, later it prints as 255! Is there a function like:
(original-number value)
that, given a number, will retrieve the original hex number?
> Hi, I don't have a clue here. I understand that Lisp is not a > base-sensitive language; it turns everything into base 10. When I > enter an integer as #xFF, later it prints as 255! Is there a function > like:
> (original-number value)
> that, given a number, will retrieve the original hex number?
> :) :) :) :)
[The following code is evil]
(defun |#x| (in sub-char num-arg) (declare (ignore sub-char num-arg)) (let* ((*read-base* 16) (integer (read in t nil t)) (symbol (intern (write-to-string integer)))) (setf (get symbol :input-type) :hex) (set symbol integer)))
Your question while humorous exposes a limitation of the Common Lisp type system. To be able to operate upon source code at the list level requires the ability to reconstruct the types of objects to a much greater level of detail than the type system provides. If there was a way to enforce types to be kept at say safety 4 then the type system itself could be used for this purpose, e.g. a new type could be defined as HEX which was a subtype of INTEGER and TYPEP could be used to check whether an INTEGER was subtype HEX. But as (a) type information can be thrown away by an implementation at any level of safety; and (b) custom types are translated to implementation types, the type system cannot be portably used for this purpose [this is a challenge: Someone please prove me wrong].
Common Lisp isn't the best language I can imagine. It's simply the best one available.
* Adam Warner | Your question while humorous exposes a limitation of the Common Lisp | type system.
Nonsense.
| To be able to operate upon source code at the list level requires the | ability to reconstruct the types of objects to a much greater level of | detail than the type system provides.
Common Lisp is not defined on the character strings that make up the source code. If you want to manipulate the character sequence that makes up the source code, you MUST NOT give it to the Common Lisp reader to convert it into Common Lisp objects.
We had this discussion endlessly and without resolution in the SGML community a decade ago. People worried ceaselessly about how they would parse SGML documents such that they could re-create the exact character sequence that made up the document. This obsession with the source form halted all work on tools to manipulate SGML documents intelligently, because it is in fact completely irrelevant what the character sequence of the source is as long as multiple forms have exactly the same semantics. Comments in particular caused a lot of grief, but you MUST realize that if comments are important to you, you MUST NOT give them to the Common Lisp reader or any other parser for which they are not only unimportant, but completely irrelevant.
Common Lisp offers its programmers the tools they need to manipulate the source at a level where the character sequences does not matter, and this tradition in the Lisp family is quite possibly the single most intelligent property of the whole Lisp tradition. (And I have not mentioned Scheme, OK?)
| Common Lisp isn't the best language I can imagine. It's simply the | best one available.
Why involve the whole world in your imagination in a negative way like this? We already know that your imagination includes thinking about the wasted cons cell of the QUOTE operator, so it is hard not to think it is somewhat lacking in working within the world just the way it is, but an «imagination» of the impossible is not useful unless you aspire to publish your fantasy writings or perhaps special effects software. Whatever you imagine, it must be realizable at some level, and you have to keep track of which parts of your imagination are going to be realizable and which are going to involve the imagination of other people. I maintain that programming /languages/ is not a good arena for unrealizable, speculative imagination.
-- Erik Naggum | Oslo, Norway
Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.
k...@ashi.footprints.net (Kaz Kylheku) writes: > Hi, I don't have a clue here. I understand that Lisp is not a > base-sensitive language; it turns everything into base 10. When I > enter an integer as #xFF, later it prints as 255! Is there a function > like:
> (original-number value)
> that, given a number, will retrieve the original hex number?
> :) :) :) :)
Why not use (format nil "~X" value) to get the string representation of the number's value in hex, which is probably what you're after.
Base 10 is convienent for humans so it makes a reasonable default, but you are in no way required to keep it set that way. You might try experimenting with *read-base* and *print-base*.
> * Adam Warner > | Your question while humorous exposes a limitation of the Common Lisp > | type system.
> Nonsense.
> | To be able to operate upon source code at the list level requires the > | ability to reconstruct the types of objects to a much greater level of > | detail than the type system provides.
> Common Lisp is not defined on the character strings that make up the > source code. If you want to manipulate the character sequence that > makes up the source code, you MUST NOT give it to the Common Lisp > reader to convert it into Common Lisp objects.
/home/adam/t/feed-the-troll.lisp: --------------------------------- (defun utility (necessities luxuries dpr-value work-hours leisure-hours) "UTILITY is composed of: 1. Ability to satify necessities of life. 2. Amount of luxuries consumed. 3. Value/utils from fulfiling digital processing requirements. 4. Hours available for leisure/non-digital processing requirements." #.+optimize+ (declare (type (double-float 0d0) necessities luxuries dpr-value work-hours leisure-hours)) (with-violation-support (* (if (>= necessities 1d0) 1d0 (sqrt (- 1d0 (square (- 1d0 necessities))))) (collect-violations (effectiveness work-hours leisure-hours)) (+ (diminishing-utility #.+base-utils-from-luxuries+ luxuries) dpr-value ;;dpr-fulfilment->dpr-value already incorporates diminishing utility (diminishing-utility #.+base-utils-from-leisure-hours+ leisure-hours))))) ---------------------------------
(defun utility (necessities luxuries dpr-value work-hours leisure-hours) "UTILITY is composed of: 1. Ability to satify necessities of life. 2. Amount of luxuries consumed. 3. Value/utils from fulfiling digital processing requirements. 4. Hours available for leisure/non-digital processing requirements." (|#.| . +optimize+) (declare (type (double-float 0.0) necessities luxuries dpr-value work-hours leisure-hours)) (with-violation-support (* (if (>= necessities 1.0) 1.0 (sqrt (- 1.0 (square (- 1.0 necessities))))) (collect-violations (effectiveness work-hours leisure-hours)) (+ (diminishing-utility (|#.| . +base-utils-from-luxuries+) luxuries) dpr-value (|;| . ";;dpr-fulfilment->dpr-value already incorporates diminishing utility") (diminishing-utility (|#.| . +base-utils-from-leisure-hours+) leisure-hours)))))
All done by the Lisp reader. Notice the unevaluated #. and the capture of comments. This could be translated back to source text. Partly a proof of concept. I can even handle the (non-)interning of symbols with a (non-keyword) package prefix. The only place comments cannot appear is within a dotted list, but I could handle this as well by further rewrites of the list reader. The code is entirely portable and coexists with standard reader definitions.
(read-list (make-string-input-stream "unknown-package:symbol)") #\( :custom nil) => Reader error at 22 on #<String-Input Stream>: Package "UNKNOWN-PACKAGE" not found. [Condition of type lisp::reader-package-error]
> We had this discussion endlessly and without resolution in the SGML > community a decade ago. People worried ceaselessly about how they > would parse SGML documents such that they could re-create the exact > character sequence that made up the document. This obsession with the > source form halted all work on tools to manipulate SGML documents > intelligently, because it is in fact completely irrelevant what the > character sequence of the source is as long as multiple forms have > exactly the same semantics. Comments in particular caused a lot of > grief, but you MUST realize that if comments are important to you, you > MUST NOT give them to the Common Lisp reader or any other parser for > which they are not only unimportant, but completely irrelevant.
> Common Lisp offers its programmers the tools they need to manipulate > the source at a level where the character sequences does not matter, > and this tradition in the Lisp family is quite possibly the single > most intelligent property of the whole Lisp tradition. (And I have > not mentioned Scheme, OK?)
> | Common Lisp isn't the best language I can imagine. It's simply the > | best one available.
> Why involve the whole world in your imagination in a negative way like > this? We already know that your imagination includes thinking about > the wasted cons cell of the QUOTE operator, so it is hard not to think > it is somewhat lacking in working within the world just the way it is, > but an «imagination» of the impossible is not useful unless you aspire > to publish your fantasy writings or perhaps special effects software. > Whatever you imagine, it must be realizable at some level, and you > have to keep track of which parts of your imagination are going to be > realizable and which are going to involve the imagination of other > people. I maintain that programming /languages/ is not a good arena > for unrealizable, speculative imagination.
By using my methods of legitimate inquiry (e.g. asking questions, like why QUOTE wastes a cons cell) as a weapon to attack me just reinforces the hypocrisy of your self-presentation as a man of reason.
One explanation that forms like the above cannot in general be evaluated as Lisp code is the insistence of Common Lisp to turn forms that return zero values into nil. I will continue to use my imagination to consider changes to Common Lisp and I will continue to work upon ideas you dismiss as unrealisable.
It's unusual for me to choose to reply to you Erik. I don't make the mistake often.
* Kaz Kylheku wrote: > Hi, I don't have a clue here. I understand that Lisp is not a > base-sensitive language; it turns everything into base 10. When I > enter an integer as #xFF, later it prints as 255! Is there a function > like:
I'm afraid you are confused. CL is really a MACLISP derivative, and as such its internal representation is, of course, octal.
* Erik Naggum wrote: > Comments in particular caused a lot of > grief, but you MUST realize that if comments are important to you, you > MUST NOT give them to the Common Lisp reader or any other parser for > which they are not only unimportant, but completely irrelevant.
If you insist that you *can* give them to the reader, then you end up with InterLISP. I remember that the Medley handling of things like #+ and #- was interesting in the sort of really bad way you'd expect.
Tim Bradshaw <t...@cley.com> wrote in message <news:ey3y8s32c5j.fsf@cley.com>... > * Kaz Kylheku wrote: > > Hi, I don't have a clue here. I understand that Lisp is not a > > base-sensitive language; it turns everything into base 10. When I > > enter an integer as #xFF, later it prints as 255! Is there a function > > like:
> I'm afraid you are confused. CL is really a MACLISP derivative, and > as such its internal representation is, of course, octal.
No way dude, the Mac was based on the 68000 chip, which uses hex (with a $ prefix, as in move.l #$FF, (A0) and all dat).
Adam Warner <use...@consulting.net.nz> writes: > (number-type 255) => :integer > (number-type #xff) => :hex > (number-type 255) => :integer
> Your question while humorous exposes a limitation of the Common Lisp type > system.
There is nothing wrong with the type system. That it does not conform to your imagination is not a limitation.
> To be able to operate upon source code at the list level requires > the ability to reconstruct the types of objects to a much greater level of > detail than the type system provides. If there was a way to enforce types > to be kept at say safety 4 then the type system itself could be used for > this purpose, e.g. a new type could be defined as HEX which was a subtype > of INTEGER and TYPEP could be used to check whether an INTEGER was subtype > HEX. But as (a) type information can be thrown away by an implementation > at any level of safety;
Type information is not thrown away. The fact that the garbage collector works is evidence of this.
> and (b) custom types are translated to implementation types, the > type system cannot be portably used for this purpose [this is a > challenge: Someone please prove me wrong].
(defstruct hex value)
(vectorp (make-hex :value 33)) => NIL
However, most implementations of defstruct allocate a linear region of memory. Some even allocate a literal vector before re-tagging it to indicate a struct.
k...@ashi.footprints.net (Kaz Kylheku) writes: > Tim Bradshaw <t...@cley.com> wrote in message <news:ey3y8s32c5j.fsf@cley.com>... > > * Kaz Kylheku wrote: > > > Hi, I don't have a clue here. I understand that Lisp is not a > > > base-sensitive language; it turns everything into base 10. When I > > > enter an integer as #xFF, later it prints as 255! Is there a function > > > like:
> > I'm afraid you are confused. CL is really a MACLISP derivative, and > > as such its internal representation is, of course, octal.
> No way dude, the Mac was based on the 68000 chip, which uses hex (with > a $ prefix, as in move.l #$FF, (A0) and all dat).
> :)
All of you are plain wrong.
It's well known that numbers are actually represented by little imps inside the computers. There are three kind of imps: the mosig imps, the lesig imps and the midsig imps, (each coming in three sexes: the littlends, the bigends, and the mixends, but strangely enough, you generally find only imps of one sex in a given computer). Some say that there are also one kind of unsig imps, but they're probably normal imps hidding out of the light. So all these little imps hold their hands in round, in groups of 32, or more often nowadays in groups of 64, but we still find some small groups of 16 or 8, or even of 9 and 36. And depending on whether they've been struck on the head by the BSD daemon, they may have a bump on the head and be crying or not. The more they cry, the higher the value of the number they represent. (That ought to be the same with politicians but it is not unfortunately).
-- __Pascal_Bourguignon__ http://www.informatimago.com/ There is no worse tyranny than to force a man to pay for what he doesn't want merely because you think it would be good for him.--Robert Heinlein http://www.theadvocates.org/
k...@ashi.footprints.net (Kaz Kylheku) wrote in message <news:cf333042.0401191729.207b5eac@posting.google.com>... > Hi, I don't have a clue here. I understand that Lisp is not a > base-sensitive language; it turns everything into base 10. When I > enter an integer as #xFF, later it prints as 255! Is there a function > like:
> (original-number value)
> that, given a number, will retrieve the original hex number?
Kaz--
I'm not sure what the smiley faces were about, but Lisp does not "turn" a number into anything but that number. Numeric bases are properties of of the representation of a number, not a property of a number.
Lisp reads in a series of characters (a representation), interprets them according to the value of *read-base*, in order to produce an integer number (actually, a representation of that number as a pattern of bits in memory, but that's as close as a computer can get to a number).
Because humans have a difficult time seeing the memory bits inside the machine, it is conventional to print out things in a representation that a human can parse. In the case of Common Lisp, it prints out numerals that denote the number in the base determined by the value of *print-base*.
#xFF is a representation of the same number represented by #b11111111, which is the same number that is represented by 255 with *read-base* bound to the number represented by #xA.
Confusing the representation of a thing with the thing itself is one of the commonest errors in thought. Common Lisp generally avoids these errors pretty well.
Consider binding *print-base* to get the effect you are looking for.
josephoswal...@hotmail.com (Joseph Oswald) writes: > k...@ashi.footprints.net (Kaz Kylheku) wrote in message <news:cf333042.0401191729.207b5eac@posting.google.com>... > > Hi, I don't have a clue here. I understand that Lisp is not a > > base-sensitive language; it turns everything into base 10. When I > > enter an integer as #xFF, later it prints as 255! Is there a function > > like:
> > (original-number value)
> > that, given a number, will retrieve the original hex number?
> Kaz--
> I'm not sure what the smiley faces were about, but Lisp does not > "turn" a number into anything but that number. Numeric bases are > properties of of the representation of a number, not a property of a > number.
> Lisp reads in a series of characters (a representation), interprets > them according to the value of *read-base*, in order to produce an > integer number (actually, a representation of that number as a pattern > of bits in memory, but that's as close as a computer can get to a > number).
> Because humans have a difficult time seeing the memory bits inside > the machine, it is conventional to print out things in a > representation that a human can parse. In the case of Common Lisp, it > prints out numerals that denote the number in the base determined by > the value of *print-base*.
> #xFF is a representation of the same number represented by > #b11111111, which is the same number that is represented by 255 with > *read-base* bound to the number represented by #xA.
> Confusing the representation of a thing with the thing itself is one > of the commonest errors in thought. Common Lisp generally avoids these > errors pretty well.
> Consider binding *print-base* to get the effect you are looking for.
what in what base should these numbers be considered to be?
[53]> (+s "nine" "five") "fourteen" [54]> (-s "eleven" "three") "eight" [55]> (*s "eight hundred and seventy-three thousand, five hundred and seventy-one" "seven hundred and sixty-six") "six hundred and sixty-nine million, one hundred and fifty-five thousand, three hundred and eighty-six"
(and check the implementation, it really uses COMMON-LISP numbers to compute the values).
-- __Pascal_Bourguignon__ http://www.informatimago.com/ There is no worse tyranny than to force a man to pay for what he doesn't want merely because you think it would be good for him.--Robert Heinlein http://www.theadvocates.org/
>> Your question while humorous exposes a limitation of the Common Lisp type >> system.
> There is nothing wrong with the type system. That it does not conform > to your imagination is not a limitation.
>> To be able to operate upon source code at the list level requires >> the ability to reconstruct the types of objects to a much greater level of >> detail than the type system provides. If there was a way to enforce types >> to be kept at say safety 4 then the type system itself could be used for >> this purpose, e.g. a new type could be defined as HEX which was a subtype >> of INTEGER and TYPEP could be used to check whether an INTEGER was subtype >> HEX. But as (a) type information can be thrown away by an implementation >> at any level of safety;
> Type information is not thrown away. The fact that the garbage > collector works is evidence of this.
>> and (b) custom types are translated to implementation types, the >> type system cannot be portably used for this purpose [this is a >> challenge: Someone please prove me wrong].
> (defstruct hex > value)
> (vectorp (make-hex :value 33)) => NIL
#S(hex :value 33) doesn't evaluate to 33. Using a defined type does:
(deftype hex () 'integer) (the hex 33) => 33
But the "presentation" type information is lost (the custom type is translated to the implementation type).
If we replace 33 with the structure #S(hex :value 33) then a program no longer evaluates the same, i.e. implementations have no understanding of how to process (numeric) objects that are wrapped up with presentation data.
I'm defining a presentation type as a piece of information attached to an object that has no effect upon standard program evaluation and semantics.
This could be implemented using structures. Many of the Common Lisp functions would have to be rewritten to discard the presentation information.
Here's a partial implementation of Kaz's question:
! is used in place of # as the dispatching macro character to avoid upsetting the standard reader. I would also store the actual text composing the number rather than just a flag for hexadecimal in a better implementation (e.g. #x00ff contains presentational information that cannot be captured by converting 255 back to hexadecimal).
[The last form demonstrates that the presentation information is discarded once an object is modified or created]
Supporting ORIG-NUM has severe performance implications. The least impact would probably come from a few type bits reserved for presentation information, and this would probably only be viable upon 64-bit platforms. Another method would be all objects attached to a presentation "pointer" (that may also provide standard type information. Under particular circumstances (low safety, good type declarations, non-use of TYPEP) these pointers could be eliminated all together. Highly declared code could even avoid type bit manipulation for integer arithmetic).
If we limit Kaz's requirements to reproducing the presentation information at the source code level then the functionality can implemented with no compiled-code performance impact:
(defstruct num hex value)
(defun |read-!x| (in sub-char num-arg) (declare (ignore sub-char num-arg)) (let* ((*read-base* 16) (value (read in t nil t))) `(a-number ,(make-num :hex t :value value))))
Now !xff evaluates and compiles to 255. But when quoted to inhibit the evaluation it's (a-number #S(num :hex t :value 255)). So the above line of source code (+ !xff 1) would be read as (+ (a-number #S(num :hex t :value 255)) 1) and when walking the list form of the code one would know when a hexadecimal number is supposed to be printed instead of a decimal one.
But a (quote #xff) does not equal (quote !xff) the !x dispatching macro can not replace #x.
>> Your question while humorous exposes a limitation of the Common Lisp type >> system.
> There is nothing wrong with the type system. That it does not conform > to your imagination is not a limitation.
>> To be able to operate upon source code at the list level requires >> the ability to reconstruct the types of objects to a much greater level of >> detail than the type system provides. If there was a way to enforce types >> to be kept at say safety 4 then the type system itself could be used for >> this purpose, e.g. a new type could be defined as HEX which was a subtype >> of INTEGER and TYPEP could be used to check whether an INTEGER was subtype >> HEX. But as (a) type information can be thrown away by an implementation >> at any level of safety;
> Type information is not thrown away. The fact that the garbage > collector works is evidence of this.
>> and (b) custom types are translated to implementation types, the >> type system cannot be portably used for this purpose [this is a >> challenge: Someone please prove me wrong].
> (defstruct hex > value)
> (vectorp (make-hex :value 33)) => NIL
#S(hex :value 33) doesn't evaluate to 33. Using a defined type does:
(deftype hex () 'integer) (the hex 33) => 33
But the "presentation" type information is lost (the custom type is translated to the implementation type).
If we replace 33 with the structure #S(hex :value 33) then a program no longer evaluates the same, i.e. implementations have no understanding of how to process (numeric) objects that are wrapped up with presentation data.
I'm defining a presentation type as a piece of information attached to an object that has no effect upon standard program evaluation and semantics.
This could be implemented using structures. Many of the Common Lisp functions would have to be rewritten to discard the presentation information.
Here's a partial implementation of Kaz's question:
! is used in place of # as the dispatching macro character to avoid upsetting the standard reader. I would also store the actual text composing the number rather than just a flag for hexadecimal in a better implementation (e.g. #x00ff contains presentational information that cannot be captured by converting 255 back to hexadecimal).
[The last form illustrates that the presentation information may (and should) be discarded within numeric computations]
Supporting ORIG-NUM has severe performance implications. The least impact would probably come from a few type bits reserved for presentation information, and this would probably only be viable upon 64-bit platforms. Another method would be all objects attached to a presentation "pointer" (that may also provide standard type information. Under particular circumstances (low safety, good type declarations, non-use of TYPEP) these pointers could be eliminated all together. Highly declared code could even avoid type bit manipulation for integer arithmetic).
If we limit Kaz's requirements to reproducing the presentation information at the source code level then the functionality can implemented with no compiled-code performance impact:
(defstruct num hex value)
(defun |read-!x| (in sub-char num-arg) (declare (ignore sub-char num-arg)) (let* ((*read-base* 16) (value (read in t nil t))) `(a-number ,(make-num :hex t :value value))))
Now !xff evaluates and compiles to 255. But when quoted to inhibit the evaluation it's (a-number #S(num :hex t :value 255)). So the above line of source code (+ !xff 1) would be read as (+ (a-number #S(num :hex t :value 255)) 1) and when walking the list form of the code one would know when a hexadecimal number is supposed to be printed instead of a decimal one.
But as (quote #xff) does not equal (quote !xff) the !x dispatching macro cannot replace #x.
* Adam Warner | By using my methods of legitimate inquiry (e.g. asking questions, like | why QUOTE wastes a cons cell) as a weapon to attack me just reinforces | the hypocrisy of your self-presentation as a man of reason.
You seem to hurt because of something I said. Had you responded less aggressively, I might have considered your pain. Now I do not.
| I will continue to use my imagination to consider changes to Common | Lisp and I will continue to work upon ideas you dismiss as | unrealisable.
It is not I who determine the realizability of your ideas. If you fight with insufficient understanding, you will not accomplish much. This ought to have concerned you if the effectiveness of your ideas is relevant to you. Considering your hostile response to my criticism and suggestions for more effective ideas and means of realizing them, it is unlikely that many people will tell you when you do something stupid, and thus you are doomed to learn only from your own mistakes. This is not a position anyone should be in unless they have worked very hard to deserve it.
| It's unusual for me to choose to reply to you Erik. I don't make the | mistake often.
Once a year seems like a good first approximation to your reply rate.
-- Erik Naggum | Oslo, Norway
Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.
Adam Warner <use...@consulting.net.nz> writes: > #S(hex :value 33) doesn't evaluate to 33.
Of course not! You wanted a HEX type that was distinguishable from CL integers.
> If we replace 33 with the structure #S(hex :value 33) then a program no > longer evaluates the same, i.e. implementations have no understanding of > how to process (numeric) objects that are wrapped up with presentation > data.
Exactly. The HEX type is different from the integer type, so you will have to define what it means to process it numerically. For instance, what does it mean to add two HEXs together? What about if the result is larger than 255? What does it mean to divide them? What about adding an integer to a HEX? Can you add OCTals to HEXs? What is the result type?
> I'm defining a presentation type as a piece of information attached to an > object that has no effect upon standard program evaluation and semantics.
>> Tim Bradshaw <t...@cley.com> wrote in message <news:ey3y8s32c5j.fsf@cley.com>... >> > * Kaz Kylheku wrote: >> > > Hi, I don't have a clue here. I understand that Lisp is not a >> > > base-sensitive language; it turns everything into base 10. When I >> > > enter an integer as #xFF, later it prints as 255! Is there a function >> > > like:
>> > I'm afraid you are confused. CL is really a MACLISP derivative, and >> > as such its internal representation is, of course, octal.
>> No way dude, the Mac was based on the 68000 chip, which uses hex (with >> a $ prefix, as in move.l #$FF, (A0) and all dat).
>> :)
> All of you are plain wrong.
From HAKMEM, ITEM 154 (Gosper):
The myth that any given programming language is machine independent is easily exploded by computing the sum of powers of 2.
- If the result loops with period = 1 with sign +, you are on a sign-magnitude machine.
- If the result loops with period = 1 at -1, you are on a twos-complement machine.
- If the result loops with period > 1, including the beginning, you are on a ones-complement machine.
- If the result loops with period > 1, not including the beginning, your machine isn't binary -- the pattern should tell you the base.
- If you run out of memory, you are on a string or Bignum system.
- If arithmetic overflow is a fatal error, some fascist pig with a read-only mind is trying to enforce machine independence. But the very ability to trap overflow is machine dependent.
By this strategy, consider the universe, or, more precisely, algebra: let X = the sum of many powers of two = ...111111 now add X to itself; X + X = ...111110 thus, 2X = X - 1 so X = -1
therefore algebra is run on a machine (the universe) which is twos-complement.
Kaz Kylheku wrote: > Hi, I don't have a clue here. I understand that Lisp is not a > base-sensitive language; it turns everything into base 10. When I > enter an integer as #xFF, later it prints as 255! Is there a function > like:
> (original-number value)
> that, given a number, will retrieve the original hex number?
> :) :) :) :)
Is this a trick question, whose answer is "RTFM *PRINT-BASE*"? :)
> If we replace 33 with the structure #S(hex :value 33) then a program no > longer evaluates the same, i.e. implementations have no understanding of > how to process (numeric) objects that are wrapped up with presentation > data.
> I'm defining a presentation type as a piece of information attached to an > object that has no effect upon standard program evaluation and semantics.
> This could be implemented using structures. Many of the Common Lisp > functions would have to be rewritten to discard the presentation > information.
If you want presentation types, you know where to find them: CLIM. The presentation type information is explicit in the program but implicit on the display.
> If you want presentation types, you know where to find them: CLIM. The > presentation type information is explicit in the program but implicit on > the display.
Thanks for the tip Timothy. I haven't used CLIM and I wasn't consciously (mis)appropriating the term.
> Tim Bradshaw <t...@cley.com> wrote in message <news:ey3y8s32c5j.fsf@cley.com>... > > * Kaz Kylheku wrote: > > > Hi, I don't have a clue here. I understand that Lisp is not a > > > base-sensitive language; it turns everything into base 10. When I > > > enter an integer as #xFF, later it prints as 255! Is there a function > > > like:
> > I'm afraid you are confused. CL is really a MACLISP derivative, and > > as such its internal representation is, of course, octal.
> No way dude, the Mac was based on the 68000 chip, which uses hex (with > a $ prefix, as in move.l #$FF, (A0) and all dat).
> :)
But MACLISP was based on Project MAC at MIT, not on the Macintosh computer. And it really was base 8 at heart. That is why you often saw integers with trailing decimal points. A trailing decimal point (with no other digits behind it) indicated a base-10 integer constant rather than a base-8 integer constant.
That meant, for example, that
(= 10 10.) => NIL (= 10 8.) => T
:D
-- Thomas A. Russ, USC/Information Sciences Institute
>> "six hundred and sixty-nine million, one hundred and fifty-five thousand, >> three hundred and eighty-six"
> FWIW, the above output is wrong - "and" should only be used between the > whole number and fractional parts, e.g.
> six hundred sixty-nine million, one hundred fifty-five thousand, three > hundred eighty-six and three tenths
That's true in US English. It's not true in British English. In the absence of a clear indication of which variety of English Pascal was intending to write, it's not reasonable to dismiss what he wrote as "wrong".
> >> "six hundred and sixty-nine million, one hundred and fifty-five thousand, > >> three hundred and eighty-six"
> > FWIW, the above output is wrong - "and" should only be used between the > > whole number and fractional parts, e.g.
It's in the same base as the input, though!
> > six hundred sixty-nine million, one hundred fifty-five thousand, three > > hundred eighty-six and three tenths
> That's true in US English. It's not true in British English. > In the absence of a clear indication of which variety of English > Pascal was intending to write, it's not reasonable to dismiss > what he wrote as "wrong".
I don't know, what are the difference in English and US numbers? But it does not matter, at least lisp ~R is consistent and it parsed the numbers and formated the output in the same language.
-- __Pascal_Bourguignon__ http://www.informatimago.com/ There is no worse tyranny than to force a man to pay for what he doesn't want merely because you think it would be good for him.--Robert Heinlein http://www.theadvocates.org/
* Pascal Bourguignon | I don't know, what are the difference in English and US numbers?
The English-speaking part of the world have enormous problem counting any higher than 20, which explains their Fred Flintstone Units and their irrational resistance to units that tends to yield measurements with values having more than 1 significant digits and their hostility towards the French for having invented smarter units, but strangely, they adopted the old French way to count large numbers, using the number of thousand groups: A million is a thousand thousand, a billion is a thousand million, a trillion is a thousand billion, etc, while the French changed their ways in 1948 to count the number of millions, so a million is a thousand thousand, a billion is a million million, and a trillion is a million billion. You may note that new trillion has three million groups, and that this pattern is a lot more sensible than the the old trillion which has /four/ thousand groups.
So when the U.S. federal deficit is two trillion dollars, is appears to Europeans to be a million times larger than it really is, which is probably the only good thing you could say about it.
-- Erik Naggum | Oslo, Norway
Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.