proposal: ⎕here

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Re: proposal: ⎕here

Postby ArrayMacNB on Tue Jan 05, 2021 2:45 pm

> In my opinion, the agile solution would seem to be to implement this in APL according to
> your own taste - you can write a 2-3 line utility function to do this quite easily. Given
> that many people have already done this...

I had a function for this pre 1990, for tradfns, which was all there were then. Given that there is no obvious way to access the current script's source, only 'baroque' solutions present themselves.

Perhaps there is a non-obvious way to access the current script's source.
ArrayMacNB
 
Posts: 9
Joined: Tue Sep 01, 2020 3:03 pm

Re: proposal: ⎕here

Postby Adam|Dyalog on Tue Jan 05, 2021 2:51 pm

Have you tried ⎕SRC⎕THIS ?
User avatar
Adam|Dyalog
 
Posts: 135
Joined: Thu Jun 25, 2015 1:13 pm

Re: proposal: ⎕here

Postby Brian|Dyalog on Tue Jan 05, 2021 5:10 pm

Years ago in my work on MiServer, I realized that I needed some way to represent blocks of JavaScript or HTML in an APL function. So, I developed a utility called ScriptFollows which treats blocks of contiguous comments as text. To make a somewhat more general utility, I've modified ScriptFollows to this...
Code: Select all
     ∇ r←TextFollows eol;⎕ML;⎕IO;lines;from;fn;dtlb;concom;remcom;delimit
[1]     ⍝ Treat contiguous following commented lines in the calling function as a text block
[2]     ⍝ Lines beginning with ⍝⍝ are stripped out
[3]     ⍝
[4]     ⍝ eol - the line ending sequence to insert between lines; ⍬ or '' will cause TextFollows to return a vector of vectors
[5]   
[6]    ⎕ML←⎕IO←1
[7]   
[8]    dtlb←{1↓¯1↓{⍵/⍨~'  '⍷⍵}' ',⍵,' '} ⍝ delete trailing/leading blanks
[9]    concom←{1↓¨⍵/⍨∧\'⍝'=⊃¨⍵} ⍝ contiguous comments
[10]   remcom←{⍵/⍨'⍝'≠⊃¨⍵} ⍝ remove lines that began with ⍝⍝
[11]   delimit←{(≢eol)↓∊eol∘,¨⍵}⍣(~0∊⍴eol) ⍝ insert delimiters if they're not empty
[12] 
[13]   :If 0∊⍴lines←(from←⊃⎕RSI).⎕NR fn←2⊃⎕SI
[14]       lines←↓from.(180⌶)fn  ⍝ 180⌶ exposes methods in classes
[15]   :EndIf
[16]   r←delimit remcom concom dtlb¨(1+2⊃⎕LC)↓lines ⍝ drop off lines up to and including this call to TextFollows
     ∇

My original version was far denser and less commented :).

Example:
Code: Select all
     ∇ z←foo
[1]    z←TextFollows ⎕UCS 10 ⍝ use linefeed to delimit lines
[2]     ⍝ This is a test
[3]     ⍝⍝ this is a comment
[4]     ⍝ This is the second line
[5]   
[6]     ⍝ This shouldn't be included
     ∇

       foo
 This is a test
 This is the second line



I've also adopted a simpler, more standalone, idiom using line labels (assumes ⎕ML ←⎕IO←1). It doesn't have the bells and whistles of TextFollows, but it suffices for most of my use cases.
Code: Select all
     ∇ z←foo
[1]   StartText:→EndText
[2]  ⍝ This is a test
[3]  ⍝ This is the second line
[4]   EndText:z←1↓∊(⎕UCS 10),¨1↓¨(1+StartText)↓EndText↑⎕NR ⊃⎕XSI
     ∇
User avatar
Brian|Dyalog
 
Posts: 116
Joined: Thu Nov 26, 2009 4:02 pm
Location: West Henrietta, NY

Re: proposal: ⎕here

Postby petermsiegel on Tue Jan 05, 2021 10:11 pm

At various times, there have been well-publicized mechanisms for sharing unsupported, but useful, tools like these within the APL community. Many of us have long since written quick "extensions" to ⎕FIX, perhaps called ∆FIX, that preprocess things like our own directives or "here-strings" inside scripts into standard APL. It's much the same as Brian describes, but easily extended using ⎕SRC, ⎕NGET, ⎕R, and ⎕FIX into any part of a script, including dfns and class :FIELD declarations.

As we all know, when sharing mechanisms get complex, expectations grow large, or there's any legal baggage, they eventually fail under their own weight. That said, Github and a bit of spit and polish might do the trick.

Cheers...
petermsiegel
 
Posts: 141
Joined: Thu Nov 11, 2010 11:04 pm

Re: proposal: ⎕here

Postby Morten|Dyalog on Wed Jan 06, 2021 7:46 am

petermsiegel wrote:As we all know, when sharing mechanisms get complex, expectations grow large, or there's any legal baggage, they eventually fail under their own weight. That said, Github and a bit of spit and polish might do the trick.


Sharing tools is one of the most important issues that I feel we need to solve as a community, in order to make real progress. This has eluded us for decades. At the moment, we're co-funding an experimental package manager which you can find at https://tatin.dev/v1/documentation. This is still very much work in progress (including the documentation), I'd be very interested in any feedback on the current design.

Dyalog is going to be experimenting with putting some of our core tools into Tatin over the next couple of months. Please nominate things you'd like us to put there.

We're hoping that this is going to become a tool which is so simple to use that it does not "collapse under its own weight". In the slightly longer term, we will also review the design of ⎕PATH & ⎕USING and see if we can come up with something new that makes it easier to refer to tools in application code, with out lots of #'s and dots all over the place.
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

Re: proposal: ⎕here

Postby ArrayMacNB on Thu Feb 25, 2021 3:03 pm

> In my opinion, the agile solution would seem to be to implement this in APL according to
> your own taste - you can write a 2-3 line utility function to do this quite easily.

Thing is, this has been implemented long ago (As a single function (PUlines) in 2011, the raw concept (FNline nxtl upto target) for much longer.

Perhaps the question is, how do I access the current script, or dfn, source?
ArrayMacNB
 
Posts: 9
Joined: Tue Sep 01, 2020 3:03 pm

Re: proposal: ⎕here

Postby Phil Last on Fri Feb 26, 2021 4:08 pm

OK. You can have an anonymous dfn or script attempt to analyse its own code but honestly I can't imagine a situation where you would except in an attempt to prove that you can't.
      {⍴⎕←⎕CR⊃⎕SI}0
0 0
f←{⍴⎕←⎕CR⊃⎕SI}
f 0
f←{⍴⎕←⎕CR⊃⎕SI}
1 15
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: proposal: ⎕here

Postby ArrayMacNB on Tue Mar 02, 2021 3:31 pm

Adam|Dyalog wrote:Have you tried ⎕SRC⎕THIS ?


I tried this very early on, found it lacking, abandoned that path. As with many other things, it may have been fixed without fanfare later on, with a recently discovered case in point: double clicking on the beginning of a line in a function edit, selects the whole line.

As Brian's solution handles, inline text being treated as code, both in auto-formatting and inadvertent execution, is an issue. More thought to follow....
ArrayMacNB
 
Posts: 9
Joined: Tue Sep 01, 2020 3:03 pm

Previous

Return to APL Chat

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest