[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sbcl-help
Subject:    Re: [Sbcl-help] two questions still unanswered
From:       Douglas Katzman via Sbcl-help <sbcl-help () lists ! sourceforge ! net>
Date:       2021-07-02 1:57:30
Message-ID: CAOrNaswxV=_4+60LBMjisMz4eQ+D+G5fuAqjPo7+0KcFP2cZyQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Thu, Jul 1, 2021 at 9:17 PM Don Cohen <don-sbcl@isis.cs3-inc.com> wrote:

>
> I posted these two one month ago.
> I thought they'd be simple to answer but so far I've not
> seen any answers.  So I'm trying again:
>
> Should these be the same?
> If so, which do you think is correct?
>
> (setf sb-ext::*evaluator-mode* :interpret)
>
> (let ((a nil)(b t)) (loop for x in a as y in b collect x))
> => NIL
>
> (setf sb-ext::*evaluator-mode* :compile)
> same form => error -- T is expected to be a list
>

An error is correct as per this:
In the *for-as-in-list* subclause, the for or as construct iterates over
the contents of a *list*
<http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#list>.
It checks for the end of the *list*
<http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#list> as
if by using *endp*
<http://www.lispworks.com/documentation/HyperSpec/Body/f_endp.htm#endp>

You might try to make the claim that it didn't have to check 'b' yet
because the termination would have happened, but that is not so.
First all the initialization forms are performed sequentially - so getting
the value of 'a' and 'b' into an iteration path counts as initialization,
wherein we check types; and then the stepping forms are performed
sequentially.  It makes no difference that the first attempt to check for
ENDP on 'a' would have terminated stepping, because the second
initialization form is not type-correct.

The older evaluator does not check types. The newer evaluator does, and
would signal a similar error as from compiled code.

* *(let ((a nil)(b t)) (loop for x in a as y in b collect x))*

debugger invoked on a TYPE-ERROR in thread

#<THREAD "main thread" RUNNING {1001478103}>:

  The value T is not of type LIST

((FLET SB-INTERPRETER::ENFORCE-SINGLE-TYPE :IN
"SYS:SRC;INTERPRETER;SPECIAL-FORMS.LISP") #<FUNCTION LISTP> T)


> (translate-logical-pathname "PERSIST:FOO.LOG")
> => #P"/data/foo.log"
>
> I was hoping for a relative pathname, #P"data/foo.log".
> How can I get that?
>

The syntax of a logical pathname is such that a leading semicolon in the
directory part means relative and absence of a leading semicolon means
absolute.
So it's sort of the opposite of unix where a leading slash means root.
I think SBCL gets it wrong, but I also think other implementations get it
wrong in different and unique ways.
This translation works for no directory components:

* *(setf (logical-pathname-translations "persist")'((";*.*"
"data/**/*.*")))*

((";*.*" "data/**/*.*"))

* *(translate-logical-pathname "PERSIST:;FOO.LOG")*

#P"data/foo.log"

But I could come up with no translation rules that work in SBCL *and* in
other lisps and allowing any number of path components such as
"PERSIST:A;B;C;FOO.LOG"

As evidence that the logical pathname itself is supposed to tell you
whether it's relative,
http://www.lispworks.com/documentation/HyperSpec/Issues/iss259_w.htm says

2a. The syntax of a logical *pathname*
<http://www.lispworks.com/documentation/HyperSpec/Body/a_pn.htm#pathname>
*namestring* <http://www.lispworks.com/documentation/HyperSpec/Body/f_namest.htm#namestring>
is as follows:

  [ host ":" ] [ ";" ] { directory ";" }* [ name ] [ "." type [ "." version ]]

If a semicolon precedes the directories, the directory component is

relative, otherwise it is absolute.

The trick will be to make some translation rule that takes relative to
relative and absolute to absolute.
In fairness to myself, I didn't try very hard because LPNs are not useful
to me and my advice is: avoid logical pathnames.
i.e. Literally don't use them and I'm not just being flippant. If almost
everything looks like POSIX these days, you gain near nothing in
portability by trying to use them.

[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Thu, Jul 1, 2021 at 9:17 PM Don Cohen &lt;<a \
href="mailto:don-sbcl@isis.cs3-inc.com">don-sbcl@isis.cs3-inc.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br> I posted these \
two one month ago.   <br> I thought they&#39;d be simple to answer but so far \
I&#39;ve not<br> seen any answers.   So I&#39;m trying again:<br><br>
Should these be the same?<br>
If so, which do you think is correct?<br>
<br>
(setf sb-ext::*evaluator-mode* :interpret)<br>
<br>
(let ((a nil)(b t)) (loop for x in a as y in b collect x))<br>
=&gt; NIL<br>
<br>
(setf sb-ext::*evaluator-mode* :compile)<br>
same form =&gt; error -- T is expected to be a \
list<br></blockquote><div><br></div><div>An error is correct as per \
this:</div><div><span style="color:rgb(0,0,0);font-family:Times;font-size:medium">In \
the  </span><i style="color:rgb(0,0,0);font-family:Times;font-size:medium">for-as-in-list</i><span \
style="color:rgb(0,0,0);font-family:Times;font-size:medium">  subclause, the  \
</span><tt style="color:rgb(0,0,0)">for</tt><span \
style="color:rgb(0,0,0);font-family:Times;font-size:medium">  or  </span><tt \
style="color:rgb(0,0,0)">as</tt><span \
style="color:rgb(0,0,0);font-family:Times;font-size:medium">  construct iterates over \
the contents of a  </span><a rel="DEFINITION" \
href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#list" \
style="font-family:Times;font-size:medium"><i>list</i></a><span \
style="color:rgb(0,0,0);font-family:Times;font-size:medium">. It checks for the end \
of the  </span><a rel="DEFINITION" \
href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#list" \
style="font-family:Times;font-size:medium"><i>list</i></a><span \
style="color:rgb(0,0,0);font-family:Times;font-size:medium">  as if by using  \
</span><a rel="DEFINITION" \
href="http://www.lispworks.com/documentation/HyperSpec/Body/f_endp.htm#endp" \
style="font-family:Times;font-size:medium"><b>endp</b></a><br></div><div><br></div><div>You \
might try to make the claim that it didn&#39;t have to check &#39;b&#39; yet because \
the termination would have happened, but that is not so.</div><div>First all the \
initialization forms are performed sequentially - so getting the value of &#39;a&#39; \
and &#39;b&#39; into an iteration path counts as initialization, wherein we check \
types; and then the stepping forms are performed sequentially.   It makes no \
difference that the first attempt to check for ENDP on &#39;a&#39; would have \
terminated stepping, because the second initialization form  is not \
type-correct.</div><div><div><br></div><div>The older evaluator  does not check \
types. The newer evaluator does, and would signal a similar error as from compiled \
code.</div><div><br></div><div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-as \
ian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">* \
</span><span class="gmail-s2" \
style="font-variant-ligatures:no-common-ligatures"><b>(let ((a nil)(b t)) (loop for x \
in a as y in b collect x))</b></span></p> <p class="gmail-p1" \
style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stre \
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">debugger invoked \
on a TYPE-ERROR in thread</span></p> <p class="gmail-p1" \
style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stre \
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">#&lt;THREAD \
&quot;main thread&quot; RUNNING {1001478103}&gt;:</span></p> <p class="gmail-p1" \
style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stre \
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span \
class="gmail-Apple-converted-space">   </span>The value T is not of type \
LIST</span></p> <p class="gmail-p1" \
style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stre \
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">((FLET \
SB-INTERPRETER::ENFORCE-SINGLE-TYPE :IN \
&quot;SYS:SRC;INTERPRETER;SPECIAL-FORMS.LISP&quot;) #&lt;FUNCTION LISTP&gt; \
T)</span></p></div><div></div></div><div><br></div><blockquote class="gmail_quote" \
style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"><br></blockquote><blockquote class="gmail_quote" \
style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex"> (translate-logical-pathname \
&quot;PERSIST:FOO.LOG&quot;)<br> =&gt; #P&quot;/data/foo.log&quot;<br>
<br>
I was hoping for a relative pathname, #P&quot;data/foo.log&quot;.<br>
How can I get that?<br></blockquote><div>  </div><div>The syntax of a logical \
pathname is such that a leading semicolon in the directory part means relative and \
absence of a leading semicolon means absolute.</div><div>So it&#39;s sort of the \
opposite of unix where a leading slash means root.</div><div><div>I think SBCL gets \
it wrong, but I also think other implementations get it wrong in different and unique \
ways.</div><div></div><div>This translation works for no directory \
components:</div><div><div><p class="gmail-p1" \
style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stre \
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">* \
</span><span class="gmail-s2" \
style="font-variant-ligatures:no-common-ligatures"><b>(setf \
(logical-pathname-translations &quot;persist&quot;)&#39;((&quot;;*.*&quot; \
&quot;data/**/*.*&quot;)))</b></span></p> <p class="gmail-p1" \
style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stre \
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">((&quot;;*.*&quot; \
&quot;data/**/*.*&quot;))</span></p> <p class="gmail-p1" \
style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stre \
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">* \
</span><span class="gmail-s2" \
style="font-variant-ligatures:no-common-ligatures"><b>(translate-logical-pathname \
&quot;PERSIST:;FOO.LOG&quot;)</b></span></p> <p class="gmail-p1" \
style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stre \
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">#P&quot;data/foo.log&quot;</span></p></div></div><div></div><div><br></div><div>But \
I could come up with no translation rules that work in SBCL *and* in other lisps and \
allowing any number of path components such as \
&quot;PERSIST:A;B;C;FOO.LOG&quot;</div><div><div><br></div><div>As evidence that the \
logical pathname itself is supposed to tell you whether it&#39;s relative, <a \
href="http://www.lispworks.com/documentation/HyperSpec/Issues/iss259_w.htm">http://www.lispworks.com/documentation/HyperSpec/Issues/iss259_w.htm</a> \
says</div><div><pre style="color:rgb(0,0,0)"><p>2a. The syntax of a logical <a \
rel="DEFINITION" href="http://www.lispworks.com/documentation/HyperSpec/Body/a_pn.htm#pathname"><b>pathname</b></a> \
<a rel="DEFINITION" href="http://www.lispworks.com/documentation/HyperSpec/Body/f_namest.htm#namestring"><b>namestring</b></a> \
is as follows:</p><p>  [ host &quot;:&quot; ] [ &quot;;&quot; ] { directory \
&quot;;&quot; }* [ name ] [ &quot;.&quot; type [ &quot;.&quot; version \
]]</p><pre><p>If a semicolon precedes the directories, the directory component \
is</p><p>relative, otherwise it is \
absolute.</p><p></p></pre></pre></div></div><div>The trick will be to make some \
translation rule that takes relative to relative and absolute to \
absolute.</div><div>In fairness to myself, I didn&#39;t try very hard because LPNs \
are not useful to me and my advice is: avoid logical pathnames.</div><div>i.e. \
Literally don&#39;t use them and I&#39;m not just being flippant. If almost \
everything looks like POSIX these days, you gain near nothing in portability by \
trying to use them.</div><div></div><div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-as \
ian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span \
class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)"></span></p></div></div><div><pre \
style="color:rgb(0,0,0)"><pre><p><br></p></pre></pre></div></div></div>





_______________________________________________
Sbcl-help mailing list
Sbcl-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic