Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #52620 > unrolled thread
| Started by | trans <transfire@gmail.com> |
|---|---|
| First post | 2016-11-14 08:42 -0800 |
| Last post | 2016-11-15 13:21 +0100 |
| Articles | 14 — 8 participants |
Back to article view | Back to comp.lang.forth
Any practical use for Atoms? trans <transfire@gmail.com> - 2016-11-14 08:42 -0800
Re: Any practical use for Atoms? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-14 10:48 -0600
Re: Any practical use for Atoms? Paul Rubin <no.email@nospam.invalid> - 2016-11-14 08:51 -0800
Re: Any practical use for Atoms? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-14 12:03 -0600
Re: Any practical use for Atoms? Paul Rubin <no.email@nospam.invalid> - 2016-11-15 22:31 -0800
Re: Any practical use for Atoms? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-11-16 03:01 -0600
Re: Any practical use for Atoms? Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> - 2016-11-14 16:39 -0500
Re: Any practical use for Atoms? trans <transfire@gmail.com> - 2016-11-14 14:12 -0800
Re: Any practical use for Atoms? Mark Wills <markwills1970@gmail.com> - 2016-11-15 03:16 -0800
Re: Any practical use for Atoms? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-11-15 17:46 +0000
Re: Any practical use for Atoms? trans <transfire@gmail.com> - 2016-11-15 21:00 -0800
Re: Any practical use for Atoms? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-16 11:55 +0100
Re: Any practical use for Atoms? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-11-17 13:32 +0000
Re: Any practical use for Atoms? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-11-15 13:21 +0100
| From | trans <transfire@gmail.com> |
|---|---|
| Date | 2016-11-14 08:42 -0800 |
| Subject | Any practical use for Atoms? |
| Message-ID | <12a2ec20-009c-4e5b-92b5-e48b0da40aa0@googlegroups.com> |
I know this is a bit off the wall, but I've been learning Erlang this month. And Erlang has "atoms" which are words that just stand for themselves. They don't represent a variable or a function -- they just are. In a way they are kind of like enums, but you don't have to pre-assign them numbers. Clojure has something similar called "keyword symbols". And Ruby has them too just called "symbols". But they are much more useful in Erlang b/c of pattern matching. So I started wondering, could Forth use such a construct in practice? Is there any value in it? Or would it be totally useless to Forth?
[toc] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2016-11-14 10:48 -0600 |
| Message-ID | <6pCdnTR0GsxRd7TFnZ2dnUU7-XmdnZ2d@supernews.com> |
| In reply to | #52620 |
trans <transfire@gmail.com> wrote: > I know this is a bit off the wall, but I've been learning Erlang > this month. And Erlang has "atoms" which are words that just stand > for themselves. They don't represent a variable or a function -- > they just are. In a way they are kind of like enums, but you don't > have to pre-assign them numbers. Clojure has something similar > called "keyword symbols". And Ruby has them too just called > "symbols". But they are much more useful in Erlang b/c of pattern > matching. > > So I started wondering, could Forth use such a construct in > practice? Is there any value in it? Or would it be totally useless > to Forth? I've definitely used such things in Forth, as unique keys for messages, etc. I think that something like CREATE FOO would do; but I guess it's possible that this won't generate unique keys on some systems, so you might need VARIABLE FOO instead. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2016-11-14 08:51 -0800 |
| Message-ID | <87d1hydmyt.fsf@nightsong.com> |
| In reply to | #52621 |
Andrew Haley <andrew29@littlepinkcloud.invalid> writes: > I guess it's possible that this won't generate unique keys on some > systems, so you might need > VARIABLE FOO > instead. Burning a runtime memory cell for each such symbol doesn't seem great. Better to write a custom defining word that maintains an internal counter etc., unless I miss something.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2016-11-14 12:03 -0600 |
| Message-ID | <Db-dnR7eQdP6YbTFnZ2dnUU7-dmdnZ2d@supernews.com> |
| In reply to | #52622 |
Paul Rubin <no.email@nospam.invalid> wrote: > Andrew Haley <andrew29@littlepinkcloud.invalid> writes: >> I guess it's possible that this won't generate unique keys on some >> systems, so you might need >> VARIABLE FOO >> instead. > > Burning a runtime memory cell for each such symbol doesn't seem > great. Better to write a custom defining word that maintains an > internal counter etc., unless I miss something. Ummm... what? How much memory is that going to save? Andrew.
[toc] | [prev] | [next] | [standalone]
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Date | 2016-11-15 22:31 -0800 |
| Message-ID | <878tskdjgn.fsf@nightsong.com> |
| In reply to | #52628 |
Andrew Haley <andrew29@littlepinkcloud.invalid> writes: >>> VARIABLE FOO instead. >> Burning a runtime memory cell for each such symbol ... > Ummm... what? How much memory is that going to save? One cell for each such symbol, I'd expect. On an MCU that's significant.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2016-11-16 03:01 -0600 |
| Message-ID | <AvSdnWZgOaH6vbHFnZ2dnUU7-W-dnZ2d@supernews.com> |
| In reply to | #52665 |
Paul Rubin <no.email@nospam.invalid> wrote: > Andrew Haley <andrew29@littlepinkcloud.invalid> writes: >>>> VARIABLE FOO instead. >>> Burning a runtime memory cell for each such symbol ... >> Ummm... what? How much memory is that going to save? > > One cell for each such symbol, I'd expect. I think not. If you have a defining word and a counter you'd still need each word to have a unique address or you wouldn't know which one it was. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | Rod Pemberton <NeedNotReplyHere@xrsevnneqk.cem> |
|---|---|
| Date | 2016-11-14 16:39 -0500 |
| Message-ID | <20161114163914.102569f9@_> |
| In reply to | #52620 |
On Mon, 14 Nov 2016 08:42:57 -0800 (PST) trans <transfire@gmail.com> wrote: > I know this is a bit off the wall, but I've been learning Erlang this > month. And Erlang has "atoms" which are words that just stand for > themselves. They don't represent a variable or a function -- they > just are. In a way they are kind of like enums, but you don't have to > pre-assign them numbers. Clojure has something similar called > "keyword symbols". And Ruby has them too just called "symbols". But > they are much more useful in Erlang b/c of pattern matching. > > So I started wondering, could Forth use such a construct in practice? > Is there any value in it? Or would it be totally useless to Forth? : NOP ; It does nothing. It does not represent a variable or function, or even a constant. It has a name. It has a unique value too. That's called an XT. As such, it would seem that it just stands for itself. Is that what you meant? Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | trans <transfire@gmail.com> |
|---|---|
| Date | 2016-11-14 14:12 -0800 |
| Message-ID | <82587e57-6dbb-4833-841c-3a08ce174e1d@googlegroups.com> |
| In reply to | #52632 |
On Monday, November 14, 2016 at 4:38:46 PM UTC-5, Rod Pemberton wrote:
> On Mon, 14 Nov 2016 08:42:57 -0800 (PST)
> trans <transfire@gmail.com> wrote:
>
> > I know this is a bit off the wall, but I've been learning Erlang this
> > month. And Erlang has "atoms" which are words that just stand for
> > themselves. They don't represent a variable or a function -- they
> > just are. In a way they are kind of like enums, but you don't have to
> > pre-assign them numbers. Clojure has something similar called
> > "keyword symbols". And Ruby has them too just called "symbols". But
> > they are much more useful in Erlang b/c of pattern matching.
> >
> > So I started wondering, could Forth use such a construct in practice?
> > Is there any value in it? Or would it be totally useless to Forth?
>
> : NOP ;
>
> It does nothing. It does not represent a variable or function, or
> even a constant. It has a name. It has a unique value too. That's
> called an XT. As such, it would seem that it just stands for itself.
> Is that what you meant?
In a way, yeah, although technically I think it is still a function even if it is a no-op. If we tried to use it, it would just up and evaporate. But if we use `'` first, then I supposed you are right.
1 2 ' NOP
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markwills1970@gmail.com> |
|---|---|
| Date | 2016-11-15 03:16 -0800 |
| Message-ID | <a60d3e71-46f7-4719-b2e7-a6c8b2c8c002@googlegroups.com> |
| In reply to | #52632 |
On Monday, 14 November 2016 21:38:46 UTC, Rod Pemberton wrote: > On Mon, 14 Nov 2016 08:42:57 -0800 (PST) > trans <transfire@gmail.com> wrote: > > > I know this is a bit off the wall, but I've been learning Erlang this > > month. And Erlang has "atoms" which are words that just stand for > > themselves. They don't represent a variable or a function -- they > > just are. In a way they are kind of like enums, but you don't have to > > pre-assign them numbers. Clojure has something similar called > > "keyword symbols". And Ruby has them too just called "symbols". But > > they are much more useful in Erlang b/c of pattern matching. > > > > So I started wondering, could Forth use such a construct in practice? > > Is there any value in it? Or would it be totally useless to Forth? > > : NOP ; > > It does nothing. It does not represent a variable or function, or > even a constant. It has a name. It has a unique value too. That's > called an XT. As such, it would seem that it just stands for itself. > Is that what you meant? > > > Rod Pemberton That's what I was thinking. If each word in the same vocab/namespace has a unique name, they can be considered atomic, and each one would have a unique key (it's XT). UNLESS some optimising compilers do clever things like give them the same run-time code because they do nothing. I think probably not though. No reason why you can't do: : atom1 ; : atom2 ; And use them. But what would you use them *for*?
[toc] | [prev] | [next] | [standalone]
| From | Gerry Jackson <gerry@jackson9000.fsnet.co.uk> |
|---|---|
| Date | 2016-11-15 17:46 +0000 |
| Message-ID | <o0fhjq$i48$1@dont-email.me> |
| In reply to | #52632 |
On 14/11/2016 21:39, Rod Pemberton wrote: > On Mon, 14 Nov 2016 08:42:57 -0800 (PST) > trans <transfire@gmail.com> wrote: > >> I know this is a bit off the wall, but I've been learning Erlang this >> month. And Erlang has "atoms" which are words that just stand for >> themselves. They don't represent a variable or a function -- they >> just are. In a way they are kind of like enums, but you don't have to >> pre-assign them numbers. Clojure has something similar called >> "keyword symbols". And Ruby has them too just called "symbols". But >> they are much more useful in Erlang b/c of pattern matching. >> >> So I started wondering, could Forth use such a construct in practice? >> Is there any value in it? Or would it be totally useless to Forth? > > : NOP ; > > It does nothing. It does not represent a variable or function, or > even a constant. It has a name. It has a unique value too. That's > called an XT. As such, it would seem that it just stands for itself. > Is that what you meant? > If you want something with a unique value and you don't care what value, you could have a definer such as : atom here constant ; atom a atom b a . b . -5655292 -5655260 ok ( GForth) which gives a unique address on systems with code and data sharing the same space. If dataspace is separate it needs a bit extra to move HERE e.g. : atom here constant 0 c, ; -- Gerry
[toc] | [prev] | [next] | [standalone]
| From | trans <transfire@gmail.com> |
|---|---|
| Date | 2016-11-15 21:00 -0800 |
| Message-ID | <9be04b9a-f8e9-4777-8bfd-0e8e08a9eead@googlegroups.com> |
| In reply to | #52661 |
On Tuesday, November 15, 2016 at 12:46:03 PM UTC-5, Gerry wrote: > On 14/11/2016 21:39, Rod Pemberton wrote: > > On Mon, 14 Nov 2016 08:42:57 -0800 (PST) > > trans <transfire@gmail.com> wrote: > > > >> I know this is a bit off the wall, but I've been learning Erlang this > >> month. And Erlang has "atoms" which are words that just stand for > >> themselves. They don't represent a variable or a function -- they > >> just are. In a way they are kind of like enums, but you don't have to > >> pre-assign them numbers. Clojure has something similar called > >> "keyword symbols". And Ruby has them too just called "symbols". But > >> they are much more useful in Erlang b/c of pattern matching. > >> > >> So I started wondering, could Forth use such a construct in practice? > >> Is there any value in it? Or would it be totally useless to Forth? > > > > : NOP ; > > > > It does nothing. It does not represent a variable or function, or > > even a constant. It has a name. It has a unique value too. That's > > called an XT. As such, it would seem that it just stands for itself. > > Is that what you meant? > > > > If you want something with a unique value and you don't care what value, > you could have a definer such as > > : atom here constant ; > atom a > atom b > a . b . -5655292 -5655260 ok ( GForth) > > which gives a unique address on systems with code and data sharing the > same space. If dataspace is separate it needs a bit extra to move HERE e.g. > > : atom here constant 0 c, ; > Of course the difference between this (as well as the other approaches suggested) is that they have to be declared. In Erlang, et al, you can just use any atom without declaring them. But maybe that's not really a big deal. In fact maybe it is better, in Forth at least, that they be declared.
[toc] | [prev] | [next] | [standalone]
| From | albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Date | 2016-11-16 11:55 +0100 |
| Message-ID | <o0hdva$r0p$1@cherry.spenarnc.xs4all.nl> |
| In reply to | #52664 |
In article <9be04b9a-f8e9-4777-8bfd-0e8e08a9eead@googlegroups.com>, trans <transfire@gmail.com> wrote: >On Tuesday, November 15, 2016 at 12:46:03 PM UTC-5, Gerry wrote: >> On 14/11/2016 21:39, Rod Pemberton wrote: >> > On Mon, 14 Nov 2016 08:42:57 -0800 (PST) >> > trans <transfire@gmail.com> wrote: >> > >> >> I know this is a bit off the wall, but I've been learning Erlang this >> >> month. And Erlang has "atoms" which are words that just stand for >> >> themselves. They don't represent a variable or a function -- they >> >> just are. In a way they are kind of like enums, but you don't have to >> >> pre-assign them numbers. Clojure has something similar called >> >> "keyword symbols". And Ruby has them too just called "symbols". But >> >> they are much more useful in Erlang b/c of pattern matching. >> >> >> >> So I started wondering, could Forth use such a construct in practice? >> >> Is there any value in it? Or would it be totally useless to Forth? >> > >> > : NOP ; >> > >> > It does nothing. It does not represent a variable or function, or >> > even a constant. It has a name. It has a unique value too. That's >> > called an XT. As such, it would seem that it just stands for itself. >> > Is that what you meant? >> > >>=20 >> If you want something with a unique value and you don't care what value,= >=20 >> you could have a definer such as >>=20 >> : atom here constant ; >> atom a >> atom b >> a . b . -5655292 -5655260 ok ( GForth) >>=20 >> which gives a unique address on systems with code and data sharing the=20 >> same space. If dataspace is separate it needs a bit extra to move HERE e.= >g. >>=20 >> : atom here constant 0 c, ; >>=20 > >Of course the difference between this (as well as the other approaches sugg= >ested) is that they have to be declared. In Erlang, et al, you can just use= > any atom without declaring them. But maybe that's not really a big deal. I= >n fact maybe it is better, in Forth at least, that they be declared. In fact it is not a big deal. In ciforth I add the automatic creation of atoms with two lines. lisp DEFINITIONS : catch-all ATOM: ; PREFIX PREVIOUS DEFINITIONS ... lisp 'catch-all PREVIOUS "" $, SWAP >NFA ! ... In the context of lisp it is unthinkably clumsy to add a declaration for all symbols in an example like guile> (define a '(we gaan naar rome en we worden kampioen)) guile> a (we gaan naar rome en we worden kampioen) So in fact it *is* a big deal. Now I'm confused. What do you mean by "big deal"? Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-11-17 13:32 +0000 |
| Message-ID | <2016Nov17.143210@mips.complang.tuwien.ac.at> |
| In reply to | #52671 |
albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) writes:
>In the context of lisp it is unthinkably clumsy to add a declaration
>for all symbols in an example like
>
>guile> (define a '(we gaan naar rome en we worden kampioen))
>guile> a
>(we gaan naar rome en we worden kampioen)
>
>So in fact it *is* a big deal.
Not in Forth. Anyway, if we want something like that, we can do it.
E.g., in <https://rosettacode.org/wiki/Topological_sort#Forth> the
input looks like this:
deps des_system_lib std synopsys std_cell_lib des_system_lib dw02 dw01 ramlib ieee
deps dw01 ieee dw01 dware gtech
deps dw02 ieee dw02 dware
deps dw03 std synopsys dware dw03 dw02 dw01 ieee gtech
...
In a Lisp program these are all atoms (see, e.g.,
<https://rosettacode.org/wiki/Topological_sort#Racket>, and the Racket
input is actually farther from the task description than the Forth
input); in the Forth program, they are all words, without a need for a
separate declaration for each word.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) |
|---|---|
| Date | 2016-11-15 13:21 +0100 |
| Message-ID | <o0eukv$ja3$1@cherry.spenarnc.xs4all.nl> |
| In reply to | #52620 |
In article <12a2ec20-009c-4e5b-92b5-e48b0da40aa0@googlegroups.com>, trans <transfire@gmail.com> wrote: >I know this is a bit off the wall, but I've been learning Erlang this month= >. And Erlang has "atoms" which are words that just stand for themselves. Th= >ey don't represent a variable or a function -- they just are. In a way they= > are kind of like enums, but you don't have to pre-assign them numbers. Clo= >jure has something similar called "keyword symbols". And Ruby has them too = >just called "symbols". But they are much more useful in Erlang b/c of patte= >rn matching. > >So I started wondering, could Forth use such a construct in practice? Is th= >ere any value in it? Or would it be totally useless to Forth? I've use for symbols in implementing lisp. One of my words accidentally has the behaviour to put its working register (AX) on the stack which is in fact the dictionary entry address which is in fact an xt. I can make cooky cutter copies of this: : SYMBOL '_ ALIAS ; S[ ] OK SYMBOL NOOT Now NOOT returns its own address/xt. S[ ] OK NOOT S[ 4440480 ] OK EXECUTE S[ 4440480 ] OK ID. NOOT S[ ] OK Yes this is useful. Groetjes Albert -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web