🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #58

Re: Optimization by programmers

#58
From: Anton Ertl
Date: Mon, 12 Oct 2026 17:10
47 lines
3025 bytes
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.

However, there are cases where this is practically relevant:

hex \ change to base #16
add \ is this a dictionary word, or a number?

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".

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
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID: <2026Oct12.191033@mips.complang.tuwien.ac.at>
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
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>

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: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Optimization by programmers
Date: Mon, 12 Oct 2026 17:10:33 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 47
Message-ID: <2026Oct12.191033@mips.complang.tuwien.ac.at>
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>
Injection-Date: Mon, 12 Oct 2026 17:27:40 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3993846"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+YtQF6+dRUSMZrU1fji4kY"; posting-host="34af6eed5d169cfbd9c0423f6ed6f4a9"
Cancel-Lock: sha1:JeZ9Jlr3RaH8/FSzGMccQMMKW2o= sha256:gUZnvCfVuF7epaEcsVCtEgBdzcYKfJQV/XyUTEPIJyA=
	sha1:lpLltW4Wr++NrmH48ALgcje+L+0= sha256:fKJYEzFxl3IVqkaBz5k77pTwxURDu9osiCI7s3imllM=
X-newsreader: xrn 10.11