Re: Obtaining the path of the application program?
Matthew Flatt <mflatt-sDh8Nw2yj/[email protected]> Thu, 26 Aug 2021 09:14:51 -0600
| Newsgroups | gmane.comp.lang.racket.user,gmane.lisp.scheme.plt |
|---|---|
| Message-ID | <[email protected]> |
The analog to the first argument to main in C is
(find-system-path 'run-file)
I think that's probably what you want.
Something closer to `get-current-source` but adapting to a run-time
file is
(variable-reference->module-source
(#%variable-reference))
Here, `(#%variable-reference)` is the primitive form that obtains a
connection to the enclosing module at run time. If you create an
executable with `raco exe`, though, the "source" of the module will be
a symbolic name instead of a path, because a module that's embedded in
an executable doesn't have a file identity anymore.
At Thu, 26 Aug 2021 07:51:35 -0700, Jeff Henrikson wrote:
> Racket users,
>=20
> Many software applications use their location in the filesystem to=20
> establish filesystem relationships between their executable file, their=
=20
> configuration and their data.=C2=A0 For this purpose, C provides the firs=
t=20
> element of the string array provided to main, python provides __file__,=
=20
> bash provides ${BASH_SOURCE[0]}, etc.
>=20
> Racket strips said value before current-command-line-arguments receives=
=20
> the subsequent command-line arguments from the operating system.
>=20
> A related value can be pulled from syntax-source as follows:
>=20
> (define-syntax (get-current-source stx)
> =C2=A0 (datum->syntax
> =C2=A0=C2=A0 (quote-syntax here)
> =C2=A0=C2=A0 (syntax-source stx)
> =C2=A0=C2=A0 stx))
>=20
> Macro get-current-source works as intended if called at program startup=
=20
> and the program is compiled on the fly with:
>=20
> racket program.rkt
>=20
> However get-current-source has the unintended property of memorizing the=
=20
> original source location if the program is compiled with raco exe (and=20
> then moved).
>=20
> Is there a way in racket to obtain the path of the application program?
>=20
>=20
> Jeff Henrikson
>=20
>=20
> --=20
> You received this message because you are subscribed to the Google Groups=
=20
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an=
email=20
> to racket-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> To view this discussion on the web visit=20
> https://groups.google.com/d/msgid/racket-users/a076dfa2-d1a5-3cda-72ae-a3=
0cdb91d
> c31%40gmail.com.
--=20
You received this message because you are subscribed to the Google Groups "=
Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to racket-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To view this discussion on the web visit https://groups.google.com/d/msgid/=
racket-users/20210826091451.14%40sirmail.smtps.cs.utah.edu.