Article View: comp.arch
Article #63Re: Optimization by programmers
From: David Brown
Date: Mon, 12 Oct 2026 19:05
Date: Mon, 12 Oct 2026 19:05
67 lines
3936 bytes
3936 bytes
On 12/10/2026 19:10, Anton Ertl wrote: > David Brown <david.brown@hesbynett.no> writes: >> Forth is arguably even better for this : >> >> : 21 42 ; >> 21 . >> 42 ok >> >> That is - you can redefine the word "21" to put the value 42 on the >> stack. Then if you ask for the number "21", you get the value 42. It >> is not an oddity of the implementation, but the way the language works. > > Yes, but used like this, it's only a curiosity; nobody does this > except to show that it can be done. > Of course :-) But it /is/ a cool curiosity! It is a natural consequence of having substantial freedom to define and redefine almost anything as a "word". And I can imagine it having a variety of uses, even for things like words that are all digits or otherwise mean something. However, my experience of Forth is quite minimal - just playing around a little - and I have no knowledge of using it for real code. > However, there are cases where this is practically relevant: > > hex \ change to base #16 > add \ is this a dictionary word, or a number? > I did not know about the "hex" word, so this is a new detail for me. Yes, I can see that having potential for confusion. > The classic ways to avoid this has been to > > 1) prefix hex numbers with 0 if they would otherwise start with a > letter. Dictionary words rarely start with digits, and when they > do, they don't conflict with hex numbers. > > 2) Use "," at the end of assembly language mnemonics, e.g. "add,": > Benefits: 1) Avoids conflicts with hex numbers. 2) For postfix > assemblers (e.g. "r0 r1 r2 add,", the "," nicely separates the > instruction from the next. But a significant number of Forth > assemblers do not follow this convention. > > In modern Forth another way is to avoid changing BASE, and just prefix > hex numbers with "$", e.g., "$add". > That looks clearer to me. Using $ for hex numbers is, I think, the first convention I learned (it was used in BBC Basic, and by its 6502 assembler). > When you do, e.g., > > hex > : add ; > > in Gforth, Gforth tells you: "warning: defined literal add as word". > It does not tell you that when you define "add" when the base is > decimal, however. > > - anton
Technical Details
Message-ID:
<11ajb1e$3ssgg$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<1177fdi$26ea4$1@dont-email.me> <11a3ofn$2ak3s$1@dont-email.me> <11a5hd5$4qb$1@reader2.panix.com> <11a5lqo$2v5bq$1@dont-email.me> <11a6870$41j$1@reader2.panix.com> <11a6a6h$37i1n$1@dont-email.me> <1791742457-5857@newsgrouper.org> <11agm4p$2tfut$1@dont-email.me> <11ahs8q$38ir0$4@dont-email.me> <11aig3c$3hdcn$1@dont-email.me> <11aiqc0$3kr94$3@dont-email.me> <2026Oct12.191033@mips.complang.tuwien.ac.at>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.arch Subject: Re: Optimization by programmers Date: Mon, 12 Oct 2026 21:05:18 +0200 Organization: A noiseless patient Spider Lines: 67 Message-ID: <11ajb1e$3ssgg$1@dont-email.me> References: <1177fdi$26ea4$1@dont-email.me> <11a3ofn$2ak3s$1@dont-email.me> <11a5hd5$4qb$1@reader2.panix.com> <11a5lqo$2v5bq$1@dont-email.me> <11a6870$41j$1@reader2.panix.com> <11a6a6h$37i1n$1@dont-email.me> <1791742457-5857@newsgrouper.org> <11agm4p$2tfut$1@dont-email.me> <11ahs8q$38ir0$4@dont-email.me> <11aig3c$3hdcn$1@dont-email.me> <11aiqc0$3kr94$3@dont-email.me> <2026Oct12.191033@mips.complang.tuwien.ac.at> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 12 Oct 2026 19:05:19 +0000 (UTC) Injection-Info: dont-email.me; logging-data="4092432"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eXCg8RIhNilSVLZjELDn+Z6EWH/DMN2o="; posting-host="711f10de653bed0662d2460037681553" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:j6EGrRvpn854e+MvBp65xjRe9w4= sha256:RCvAF7ZrEt6nEhOFQKptc+WOW/wdAPcEujLYn/yfHRc= sha1:lm62Prm+nJUM6Skee21kmGzkUkk= sha256:o+oZ/24K0sPDap9YbQdPiqass1dwoMac7j5wM8tPZCA= Content-Language: en-GB In-Reply-To: <2026Oct12.191033@mips.complang.tuwien.ac.at>