Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #28399
| From | Gerry Jackson <gerry@jackson9000.fsnet.co.uk> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Pass a name string to a CREATE DOES> via user input |
| Date | 2014-02-13 23:56 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <ldjm3d$aut$1@dont-email.me> (permalink) |
| References | <1b6c0627-940b-4ea8-b035-48d16f9bbbfd@googlegroups.com> |
On 13/02/2014 01:50, hank.lenzi@gmail.com wrote: > Hello -- > > Here's the problem. I'd like to be able to associate a database indentifier with a very long name. > > I can do that with: > > : $NAME CREATE 46 ( . ) WORD C@ 1+ ALLOT ; Using WORD like this is not portable as WORD is not guaranteed to save a counted string at to HERE, although many Forths do so. So you ought to copy the string there yourself. In that case it is better to use PARSE instead of WORD ( and [CHAR] . instead of 46) e.g. : $name create [char] . parse dup c, here swap chars dup allot move ; An alternative to get the string on the rest of the line is to use SOURCE e.g. : $name create source >in @ /string dup c, here swap chars dup allot move postpone \ ; But that is a bit longer. If you really want to have a named definition returning a (caddr u) string you can get the system to store it e.g. : $name : [char] . parse postpone sliteral postpone ; ; In all these versions of $name it might be a good idea to skip leading spaces before parsing because, if there is more than 1 space before the string, it/they will be included in the string > > The user can do something like: > > $NAME STJOHN100 Mary Josephine Alcantara Souza de Aguiar. > > At this, point, of course, STJOHN100 is a word. > > The problem is that the user has to enter "$NAME". Is there a way to get a string from user input (say, via PAD) and then pass *that* to the CREATE part? > To put this in a loop you can do (REFILL works with different input sources and so is better than ACCEPT): : get-line ( -- u ) refill 0= abort" Early end of file" source nip ; : save-data ( -- ) begin get-line while $name repeat ; save-data STJOHN100 Mary Josephine Alcantara Souza de Aguiar FRDBLG Fred Bloggs \ end-data Note that input is terminated by the blank line above If there is nothing at the end of the line after the string the terminating . is unnecessary as PARSE or WORD will parse to the end of the line. > I've tried dropping "c-addr u" on the stack, and then doing "CREATE , , " (all the rest the same). > > Why do this? For instance, you could create a procedure that would use $NAME automatically (e.g., in a loop). This would sort of work like an iterator in some other languages, I suppose. > > TIA, > Hank Lenzi > -- Gerry
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Pass a name string to a CREATE DOES> via user input hank.lenzi@gmail.com - 2014-02-12 17:50 -0800
Re: Pass a name string to a CREATE DOES> via user input "Elizabeth D. Rather" <erather@forth.com> - 2014-02-12 16:01 -1000
Re: Pass a name string to a CREATE DOES> via user input Julian Fondren <julian.fondren@gmail.com> - 2014-02-12 18:14 -0800
Re: Pass a name string to a CREATE DOES> via user input "Elizabeth D. Rather" <erather@forth.com> - 2014-02-12 16:36 -1000
Re: Pass a name string to a CREATE DOES> via user input Mark Wills <markrobertwills@yahoo.co.uk> - 2014-02-13 00:42 -0800
Re: Pass a name string to a CREATE DOES> via user input Elizabeth D Rather <erather@forth.com> - 2014-02-12 22:55 -1000
Re: Pass a name string to a CREATE DOES> via user input Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-02-13 23:56 +0000
Re: Pass a name string to a CREATE DOES> via user input hank.lenzi@gmail.com - 2014-02-13 18:20 -0800
Re: Pass a name string to a CREATE DOES> via user input Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-02-14 08:02 +0000
Re: Pass a name string to a CREATE DOES> via user input "Elizabeth D. Rather" <erather@forth.com> - 2014-02-13 22:18 -1000
Re: Pass a name string to a CREATE DOES> via user input Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-02-14 10:37 +0000
Re: Pass a name string to a CREATE DOES> via user input "Elizabeth D. Rather" <erather@forth.com> - 2014-02-14 09:53 -1000
Re: Pass a name string to a CREATE DOES> via user input Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-02-14 22:16 +0000
Re: Pass a name string to a CREATE DOES> via user input albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-02-14 12:17 +0000
Re: Pass a name string to a CREATE DOES> via user input hank.lenzi@gmail.com - 2014-02-15 11:16 -0800
Re: Pass a name string to a CREATE DOES> via user input Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-02-15 22:54 +0000
Re: Pass a name string to a CREATE DOES> via user input Coos Haak <chforth@hccnet.nl> - 2014-02-16 00:24 +0100
Re: Pass a name string to a CREATE DOES> via user input Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-02-16 08:01 +0000
Re: Pass a name string to a CREATE DOES> via user input "Elizabeth D. Rather" <erather@forth.com> - 2014-02-15 16:27 -1000
Re: Pass a name string to a CREATE DOES> via user input Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-02-16 08:21 +0000
Re: Pass a name string to a CREATE DOES> via user input stephenXXX@mpeforth.com (Stephen Pelc) - 2014-02-16 10:58 +0000
Re: Pass a name string to a CREATE DOES> via user input "Elizabeth D. Rather" <erather@forth.com> - 2014-02-13 18:28 -1000
csiph-web