Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #134855

Re: Parsing a file name with spaces

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Parsing a file name with spaces
Date 2026-04-02 14:43 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2026Apr2.164319@mips.complang.tuwien.ac.at> (permalink)
References (8 earlier) <10qgp41$3ejgv$2@dont-email.me> <2026Apr1.095400@mips.complang.tuwien.ac.at> <10qiv6o$5hjd$1@dont-email.me> <2026Apr2.103433@mips.complang.tuwien.ac.at> <10qlmqo$12kqq$1@dont-email.me>

Show all headers | View raw


Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>Not really. Let's say you wanted a word which operates on an arbitrary 
>number of files (which fit on a single line).

Such a requirement has not surfaced for my Forth programs in the last 4
decades.

If you have such a requirement, PARSE-NAME is good enough, because
"modern file paths" (i.e., those that tend to contain spaces) tend to
be too long to fit several comfortably on a single line.  E.g., here's
one of the files I have on my file system:

/home/anton/stuko/curricula/Informatik/Masterstudium_Medizinische_Informatik/module/MethodologicalFoundationsOfPublicHealthInformatics.tex

And these are not even using spaces.  If this was using spaces instead
of CamelCase, it would be even longer.  Here's another one:

/home/anton/stuko/curricula/Informatik/Masterstudium_Software_Engineering/module/AdvancedTopicsInDistributedAndNextGenerationComputing.tex

Even a single component of this path is up to 53 characters.

Let's take a look at file names that actually contain spaces:

/home/cds/tracks/1999 Compilation--Short Music for Short People/99.Caustic Soda; Misfits; Wizo--Welcome To Dumpsville, Population: You; NY Ranger; The Count.ogg

That's a nasty one, because this CD contains more then 99 songs, but
the CD format only supports 99 tracks, so the last track contains
several songs.  Let's take a look at another one:

/home/cds/tracks/2007 Marilyn Manson--Eat Me, Drink Me/12.Heart-Shaped Glasses (When The Heart Guides The Hand) (Inhuman Remix By Jade E Puget).ogg

The users and programs that create filenames with spaces, whether it
is scripts, as in the track cases, or whether it is users using GUIs
don't avoid longish file names, unlike human CLI users.

So if you design an interface for human CLI users like

><wordname> <file_1> <file_2> <file_3> ... <file_n>

then I see little point in designing it for filenames coming out of
GUIs etc.  Just use PARSE-NAME (appropriate for CLI filenames), and
leave file names containing spaces to a word like

>S" <file_1>"  S" <file_2>  S" <file_3>" ... S" <file_n>" n wordname

Here the user can write

"MethodologicalFoundationsOfPublicHealthInformatics.tex"
"99.Caustic Soda; Misfits; Wizo--Welcome To Dumpsville, Population: You; NY Ranger; The Count.ogg"
"12.Heart-Shaped Glasses (When The Heart Guides The Hand) (Inhuman Remix By Jade E Puget).ogg"
3 wordname

[note that these are only the last components of several of the file
names shown above]

(or do it with S" if you want, and include something like SAVE-MEM if
necessary on your system)

This still does not look particularly neat, but better than putting
all the file names in one line (and AFAIK some widely used Forth
systems still have hard limits on line length, and do not even do
proper error reporting when the limits are exceeded).

Plus, you can use comments between file names, which parsing words
usually do not support.

>Forth is often advertised as a useful language for writing DSLs. Parsing 
>words are critical for writing a DSL when it doesn't use stack passing 
>of parameters.

Use stack-passing of parameters.  For a variable number, a pair of
words that does the counting for you may be useful; something like:

stack<
...
>2stack#

implemented nestably as

variable initial-stack-depth

: stack< ( -- old )
  initial-stack-depth @
  depth initial-stack-depth ! ;

: >stack# ( old i*x -- i*x u )
  depth initial-stack-depth @ - dup 1+ roll initial-stack-depth ! ;

: >2stack# ( old i*x -- i*x u )
  >stack# 2/ ; \ maybe add a chack for evenness

If you don't require nesting, this can be simplified by leaving all
the "old" handling away.

As for being useful for DSLs, I have often seen the claim, but not
examples.  At least not examples where some syntax that requires
significant parsing is involved.  If you go there, you no longer can
mix Forth and DSL code, and Forth loses a lot of its benefits.

- 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: https://forth-standard.org/
EuroForth 2025 proceedings: http://www.euroforth.org/ef25/papers/

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-24 08:51 -0500
  Re: Parsing a file name with spaces peter <peter.noreply@tin.it> - 2026-03-24 15:24 +0100
  Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-25 01:28 +1100
    Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-25 21:24 +1100
      Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-03-25 14:57 +0100
  Re: Parsing a file name with spaces Stephen Pelc <stephen@vfxforth.com> - 2026-03-24 15:55 +0000
    Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-25 10:05 -0500
      Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-25 16:56 +0000
        Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-25 15:22 -0500
          Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-28 12:02 +1100
            Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-03-28 08:54 +0100
              Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-28 19:37 +1100
                Re: Parsing a file name with spaces sjack@dontemail.me (sjack) - 2026-03-28 15:10 +0000
          Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-28 18:59 +0000
            Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-29 11:11 +1100
              Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-29 09:24 +0000
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-03-29 13:03 +0200
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-29 22:07 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-29 16:08 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-30 09:34 +1100
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-31 09:18 +1100
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-30 20:41 -0500
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-03-31 14:14 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-31 07:36 +0000
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-03-31 14:03 +0200
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-01 12:22 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-01 08:22 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-01 20:06 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-02 06:05 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-02 18:09 +1100
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-04-02 13:54 +0200
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-03 11:57 +1100
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-04-03 11:44 +0200
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-04 00:23 +1100
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-05 10:55 +1000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-05 11:50 +1000
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-04-01 12:25 +0200
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-02 00:07 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-31 07:54 +0000
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-31 05:03 -0500
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-31 10:32 +0000
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-31 10:26 -0500
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-04-01 00:19 +0200
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-31 18:04 -0500
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-01 07:54 +0000
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-01 06:23 -0500
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-02 08:34 +0000
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-02 07:18 -0500
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-02 14:43 +0000
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-02 20:52 -0500
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-04-03 11:40 +0200
                Re: Parsing a file name with spaces sjack@dontemail.me (sjack) - 2026-04-04 06:21 +0000
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-04-04 08:00 -0500
                Re: Parsing a file name with spaces sjack@dontemail.me (sjack) - 2026-04-04 22:01 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-07 10:23 +1000
                Re: Parsing a file name with spaces sjack@dontemail.me (sjack) - 2026-04-07 14:26 +0000
                Re: Parsing a file name with spaces sjack@dontemail.me (sjack) - 2026-04-07 15:05 +0000
                Re: Parsing a file name with spaces sjack@dontemail.me (sjack) - 2026-04-07 17:09 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-08 12:25 +1000
                Re: Parsing a file name with spaces Stephen Pelc <stephen@vfxforth.com> - 2026-04-09 10:22 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-01 19:13 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-02 05:55 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-02 17:44 +1100
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-03-31 13:41 +0200
                Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-31 10:18 -0500
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-01 11:28 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-01 08:17 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-01 19:42 +1100
                Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-04-01 12:13 +0200
                Re: Parsing a file name with spaces Gerry Jackson <do-not-use@swldwa.uk> - 2026-04-01 19:43 +0100
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-02 12:18 +1100
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-02 12:43 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-02 09:07 +0000
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-02 21:50 +1100
                Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-04-02 09:11 +0000
                Re: Parsing a file name with spaces Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-12 19:37 +0200
                Re: Parsing a file name with spaces Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-12 19:44 +0200
                Re: Parsing a file name with spaces dxf <dxforth@gmail.com> - 2026-04-13 11:05 +1000
                Re: Parsing a file name with spaces Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-14 14:45 +0200
                Re: Parsing a file name with spaces Hans Bezemer <the.beez.speaks@gmail.com> - 2026-04-15 15:51 +0200
  Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-24 17:58 +0000
    Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-24 13:41 -0500
      Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-24 20:40 +0000
        Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-24 20:26 -0500
  Re: Parsing a file name with spaces albert@spenarnc.xs4all.nl - 2026-03-25 10:37 +0100
    Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-25 05:13 -0500
    Re: Parsing a file name with spaces Bigtreeman <treecolin@gmail.com> - 2026-03-26 09:16 +1000
      Re: Parsing a file name with spaces Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-03-25 20:57 -0500
      Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-28 19:14 +0000
        Re: Parsing a file name with spaces Bigtreeman <treecolin@gmail.com> - 2026-03-29 12:22 +1000
          Re: Parsing a file name with spaces Paul Rubin <no.email@nospam.invalid> - 2026-03-28 20:55 -0700
            Re: Parsing a file name with spaces Bigtreeman <treecolin@gmail.com> - 2026-03-29 17:00 +1000
              Re: Parsing a file name with spaces Paul Rubin <no.email@nospam.invalid> - 2026-03-29 19:05 -0700
                Re: Parsing a file name with spaces Bigtreeman <treecolin@gmail.com> - 2026-03-30 21:58 +1000
            Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-29 09:52 +0000
          Re: Parsing a file name with spaces anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2026-03-29 09:32 +0000
            Re: Parsing a file name with spaces Bigtreeman <treecolin@gmail.com> - 2026-03-30 22:10 +1000
  Re: Parsing a file name with spaces Hans Bezemer <the.beez.speaks@gmail.com> - 2026-03-29 13:22 +0200

csiph-web