Re: Obtaining the path of the application program?

Ryan Culpepper <[email protected]> Thu, 26 Aug 2021 17:17:36 +0200
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <CANy33q=-suP4a_GKtBeBYWUS6P=-WNvDo5mFa1cAgFWUi6bEYQ@mail.gmail.com>
--0000000000008caff405ca77dec4
Content-Type: text/plain; charset="UTF-8"

Usually, if you want to refer to data files etc relative to the current
module's file, a good solution is to use `define-runtime-path`. It uses
`#%variable-reference` as the basis for its implementation, but adds other
features like cooperation with `raco exe` (see docs for
`define-runtime-path` near "an executable creator").

Ryan


On Thu, Aug 26, 2021 at 4:51 PM Jeff Henrikson <[email protected]> wrote:

> Racket users,
>
> Many software applications use their location in the filesystem to
> establish filesystem relationships between their executable file, their
> configuration and their data.  For this purpose, C provides the first
> element of the string array provided to main, python provides __file__,
> bash provides ${BASH_SOURCE[0]}, etc.
>
> Racket strips said value before current-command-line-arguments receives
> the subsequent command-line arguments from the operating system.
>
> A related value can be pulled from syntax-source as follows:
>
> (define-syntax (get-current-source stx)
>   (datum->syntax
>    (quote-syntax here)
>    (syntax-source stx)
>    stx))
>
> Macro get-current-source works as intended if called at program startup
> and the program is compiled on the fly with:
>
> racket program.rkt
>
> However get-current-source has the unintended property of memorizing the
> original source location if the program is compiled with raco exe (and then
> moved).
> Is there a way in racket to obtain the path of the application program?
>
>
> Jeff Henrikson
>
>
> --
> 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
> email to racket-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/a076dfa2-d1a5-3cda-72ae-a30cdb91dc31%40gmail.com
> <https://groups.google.com/d/msgid/racket-users/a076dfa2-d1a5-3cda-72ae-a30cdb91dc31%40gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 email to racket-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CANy33q%3D-suP4a_GKtBeBYWUS6P%3D-WNvDo5mFa1cAgFWUi6bEYQ%40mail.gmail.com.

--0000000000008caff405ca77dec4
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Usually, if you want to refer to data files etc relat=
ive to the current module&#39;s file, a good solution is to use `define-run=
time-path`. It uses `#%variable-reference` as the basis for its implementat=
ion, but adds other features like cooperation with `raco exe` (see docs for=
 `define-runtime-path` near &quot;an executable creator&quot;).</div><div><=
br></div><div>Ryan</div><div><br></div></div><br><div class=3D"gmail_quote"=
><div dir=3D"ltr" class=3D"gmail_attr">On Thu, Aug 26, 2021 at 4:51 PM Jeff=
 Henrikson &lt;<a href=3D"mailto:[email protected]">[email protected]=
</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 =20

   =20
 =20
  <div>
    <div lang=3D"x-unicode">
      <p>Racket users,<br>
        <br>
        Many software applications use their location in the filesystem
        to establish filesystem relationships between their executable
        file, their configuration and their data.=C2=A0 For this purpose, C
        provides the first element of the string array provided to main,
        python provides __file__, bash provides ${BASH_SOURCE[0]}, etc.<br>
        <br>
        Racket strips said value before current-command-line-arguments
        receives the subsequent command-line arguments from the
        operating system.<br>
        <br>
        A related value can be pulled from syntax-source as follows:<br>
      </p>
      <blockquote>(define-syntax (get-current-source stx)<br>
        =C2=A0 (datum-&gt;syntax<br>
        =C2=A0=C2=A0 (quote-syntax here)<br>
        =C2=A0=C2=A0 (syntax-source stx)<br>
        =C2=A0=C2=A0 stx))<br>
      </blockquote>
      <p>Macro get-current-source works as intended if called at program
        startup and the program is compiled on the fly with:<br>
      </p>
      <blockquote>racket program.rkt<br>
      </blockquote>
      <p>However get-current-source has the unintended property of
        memorizing the original source location if the program is
        compiled with raco exe (and then moved).</p>
      Is there a way in racket to obtain the path of the application
      program?
      <p><br>
      </p>
      <p>Jeff Henrikson</p>
      <p><br>
      </p>
    </div>
  </div>


<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;Racket Users&quot; group.<br>
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:racket-users+unsubscribe-/[email protected]" target=
=3D"_blank">racket-users+unsubscribe-/[email protected]</a>.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/racket-users/a076dfa2-d1a5-3cda-72ae-a30cdb91dc31%40gmail.com?ut=
m_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">https://groups.=
google.com/d/msgid/racket-users/a076dfa2-d1a5-3cda-72ae-a30cdb91dc31%40gmai=
l.com</a>.<br>
</blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;Racket Users&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:racket-users+unsubscribe-/[email protected]">racket=
-users+unsubscribe-/[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/racket-users/CANy33q%3D-suP4a_GKtBeBYWUS6P%3D-WNvDo5mFa1cAgFWUi6=
bEYQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://group=
s.google.com/d/msgid/racket-users/CANy33q%3D-suP4a_GKtBeBYWUS6P%3D-WNvDo5mF=
a1cAgFWUi6bEYQ%40mail.gmail.com</a>.<br />

--0000000000008caff405ca77dec4--