Page 2 of 3

Re: extra stack operators

Posted: Thu Feb 14, 2019 1:09 am
by JimBoyd
chitselb wrote:
on the OLPC wiki, there's NIP ( a b -- b ) and TUCK ( a b -- b a b ) and -ROT ( a b c -- c a b ) which I call LROT, but what is the word which has the stack diagram ( a b c -- b a c ) ? Is it UNDER?
I hope the name UNDER does not get confused with UNDER+ which has the stack effect ( a b c -- a+c b ). I don't remember where I saw UNDER+ , but I've found it useful and included it in Fleet Forth's kernel since day one.

Cheers,
Jim

Re: extra stack operators

Posted: Thu Feb 14, 2019 4:47 am
by whartung
barrym95838 wrote:
I would be tempted to name them bca, bac, cab, and cba, but I have a perverse affinity for three-letter mnemonics. :wink:
I was thinking the same thing.

Lisp actually does exactly this with CAR and CDR combinations.

Such that you have several things like:
Quote:
(CAAR x) == (CAR (CAR x))
(CADR x) == (CAR (CDR x))
(CDDR x) == (CDR (CDR x))
(CDAR x) == (CDR (CAR x))
I think many have all the combinations out to 5 letters (CAAAR).

Re: extra stack operators

Posted: Thu Feb 14, 2019 6:49 am
by rwiker
whartung wrote:
barrym95838 wrote:
I would be tempted to name them bca, bac, cab, and cba, but I have a perverse affinity for three-letter mnemonics. :wink:
I was thinking the same thing.

Lisp actually does exactly this with CAR and CDR combinations.

Such that you have several things like:
Quote:
(CAAR x) == (CAR (CAR x))
(CADR x) == (CAR (CDR x))
(CDDR x) == (CDR (CDR x))
(CDAR x) == (CDR (CAR x))
I think many have all the combinations out to 5 letters (CAAAR).

Almost right - Common Lisp has up to 6 letters (i.e, sequences of A's and D's up to length 4). That makes up 2^1+2^2+2^3+2^4 = 30 of Common Lisp's set of 978 symbols.

Re: extra stack operators

Posted: Fri Feb 22, 2019 8:38 pm
by JimBoyd
chitselb wrote:
FLIP ( a b c -- b a c )
FLOP ( a b c -- c b a )

I'm going to call them FLIP and FLOP for now, until I find out what the names are supposed to be.
The word you are calling FLOP is called NUTATE in Leo Brodie's book "Thinking Forth". I think it was just in the context of an example though.

Re: extra stack operators

Posted: Fri Feb 22, 2019 8:50 pm
by JimBoyd
theGSman wrote:
programandala.net wrote:
I don't think it would be practical, even feasible. There are many different stack operations you can do, and most of them can be defined using others. The standard operations have names related to their functions, because the functions are simple.
I think that what chitselb means is that every stack manipulation should have a name, not that every conceivable stack manipulation (no matter how rarely used) should be implemented in a Forth system. It is a simple matter to write a CODE word for any manipulation that isn't in your Forth system but is likely to be used a lot in a program. I have often found 2PICK to be such a word.
Yes and your favorites could be kept available in source form.
Quote:
programandala.net wrote:
That's the problem I just mentioned. It would be hard to remember not only which one is `flop` and which one is `flip`, but also what they actually do!
for "flop" I would probably use ROTSWAP if I needed the word or SWAPUNDER if the former name was not descriptive enough.
"flip" would probably sound better as 3REVERSE. (I hope I didn't get "flip" and "flop" mixed up. :mrgreen: )
I believe FLIP is ROT SWAP , and I agree, ROTSWAP is a better name. It has the virtue of telling what it does just like DUP>R takes the place of DUP >R .

Re: extra stack operators

Posted: Sun Nov 01, 2020 10:34 pm
by JimBoyd
theGSman wrote:
I have often found 2PICK to be such a word.

Is that equivalent to the phrase 2 PICK or is it a double number version of PICK ?

Re: extra stack operators

Posted: Sun Nov 01, 2020 10:53 pm
by GARTHWILSON
JimBoyd wrote:
theGSman wrote:
I have often found 2PICK to be such a word.
Is that equivalent to the phrase 2 PICK or is it a double number version of PICK ?
I have 2_PICK and DPICK.

Re: extra stack operators

Posted: Sun Nov 01, 2020 11:04 pm
by GARTHWILSON
Dr Jefyll wrote:
Mike, the TLM's you propose are valid hex numbers. Could get (a little too) interesting... :)

It should be fine in Forth since the dictionary is searched first, and #INT is only called if something wasn't found in the dictionary, to see if it's a valid number in the current base. So for example FACE, BAD, FEED, DEAD, ADD, and other such names, if defined, would never be confused for a hex number either.

Re: extra stack operators

Posted: Sun Nov 01, 2020 11:05 pm
by JimBoyd
Sadly, the Commodore 64 lacks the underscore character.

Re: extra stack operators

Posted: Sun Nov 01, 2020 11:11 pm
by JimBoyd

I realize I could go with something like 2.PICK but a name with a dot in it ( if it's not used for numeric output ) seems more appropriate for SamCoVT's idea of organizing constant names around what they go to.

Re: extra stack operators

Posted: Sun Nov 01, 2020 11:13 pm
by GARTHWILSON
JimBoyd wrote:
Sadly, the Commodore 64 lacks the underscore character.
Early Forths used the hyphen for that function, and it has carried into modern Forths too.  I think the underscore character works better though.  For characters that aren't on the keyboard, many systems offer easy ways to type them in.  When I'm in my MultiEdit [1] editor, I hold <Alt> while typing the three-digit decimal DOS/ANSI [Edit: that should say IBM437] character number, like 248 for the ° symbol or 241 for the ± symbol.  The ones I use most often I remember; but <Alt>A (for "ASCII," even though real ASCII ends at 127) brings up the chart for when I don't remember the number.

[1] Edit, 8/9/25:  I just found out, from the Wikipedia article that MultiEdit is defunct, due to the heart-attack death of the man who really made it go, and that even the website has been gone since Aug 2022.

Re: extra stack operators

Posted: Wed Nov 04, 2020 8:35 pm
by JimBoyd

Not only is the underscore character not on the C64 keyboard, it is not even in the PETSCII character set.
I like the idea of 2PICK being syntactically equivalent to 2 PICK while DPICK is the double number version of PICK .

Re: extra stack operators

Posted: Wed Nov 04, 2020 9:13 pm
by JimBoyd

I just checked the documentation for Mosaic Forth versions 4.0 and 4.2 .
The stack effect for DPICK is this.
DPICK ( d wn-1 . . . w1 w0 +n -- d wn-1 . . . w1 w0 d )
The documentation states that it copies the double number whose most significant cell is nth item on the data stack ( 0-based not including n) to the top of the stack.
0 DPICK is equivalent to 2DUP
2 DPICK is equivalent to 2OVER
1 DPICK will copy a double number that is just below a single number
( d w -- d w d )

Re: extra stack operators

Posted: Wed Nov 04, 2020 9:23 pm
by GARTHWILSON
JimBoyd wrote:
Not only is the underscore character not on the C64 keyboard, it is not even in the PETSCII character set.
Does the ROM get copied to RAM, such that you can alter the character set? My HP-71 lets you load in different character sets, telling it what dots to turn on for each; so although it comes with the ROMAN-8 set as standard, I did the DOS/ANSI [Edit: that should say IBM437] set since I now always use Epson dot-matrix printers with it.

Re: extra stack operators

Posted: Fri Nov 06, 2020 10:04 am
by JeeK
GARTHWILSON wrote:
JimBoyd wrote:
Not only is the underscore character not on the C64 keyboard, it is not even in the PETSCII character set.
Does the ROM get copied to RAM, such that you can alter the character set? My HP-71 lets you load in different character sets, telling it what dots to turn on for each; so although it comes with the ROMAN-8 set as standard, I did the DOS/ANSI set since I now always use Epson dot-matrix printers with it.
Code 95 of "_" is the left arrow character on a C64 (PETSCII-Code). It doesn't look nice, but the character is displayed and can be typed in.
Someone might redefine this character to a "_" to get the "real" feeling.