Need Some Design Help

Write your own primitives in APL

Need Some Design Help

PostPosted by forummaster » Fri Jan 16, 2009 11:39 am

Magic functions are APL functions internal to the interpreter. They are invoked by the interpreter in the current workspace whenever needed to perform a task that is easier to write in APL than in the native language of the interpreter (in the case of NARS2000, the native language is C).
For example, the Without function (L~R) is written as a magic function. To see the code used, type



¯2 ⎕cr '#DydTilde'
Z←L F R
Z←(~L∊R)/L


Also, the Rank operator is a magic function:


¯2 ⎕cr '#DydRank'
Z←L (LO F Y) R;O
Y←1↓⌽3⍴⌽Y
O←(⍴⍴L),⍴⍴R
Y←(-O)⌈O⌊Y
Z←(⊂[⍳-1↑Y]L)LO¨⊂[⍳-1↓Y]R⋄→0
⎕PROTOTYPE:Z←⊃(⊂[⍳-1↑Y]¨0⍴⊂L)LO¨¨⊂[⍳-1↓Y]¨0⍴⊂R


The next step is to expose this capability to the end user so she can write her own APL function (or group of functions) and associate them with a symbol or system name. Here's where the design work begins.



  • I'd like to be able to combine multiple APL functions as a single magic function.

  • I'd like a way to make the local vars to the magic function invisible to the normal system functions so the MF can reference global vars without fear of localization issues.

  • There needs to be a way to associate the APL functions with a symbol (or system name) and to mark that symbol as a monadic/dyadic/ambivalent function/operator.

  • There needs to be a way to call the previous meaning of the symbol/system name so as to allow overlays on top of existing symbols/system names.

forummaster
 
Posts: 555
Joined: Wed Jan 23, 2013 1:00 pm

Magic functions

PostPosted by Lobachevsky » Wed Jan 28, 2009 4:36 pm

Maybe I've been using Dyalog APL too long, but it seems that something like a Dyalog namespace is what is needed to make this work well.


Suppose every primitive definition has its own namespace. #.WITHOUT, #.RANK and the main function or operator is named the same as the namespace


* Combine APL functions - no problem


* Global names: #.[]IO, #.GLOBAL, etc.


* Specify the symbol: #.WITHOUT.[]SYMBOL := '~' '[]WITHOUT'


* Previous meaning: Why do you really need this? Go into the namespace and make the old function a subroutine.



I always thought that STSC/Manugistics/APL2000's ]CMDS and Dyalogs namespaces would be a good marriage.


APLX has a lighter weight namespace-like object which is also worth looking at.

Lobachevsky
 
Posts: 2
Joined: Wed Jan 28, 2009 3:49 pm

Need Some Design Help

PostPosted by forummaster » Thu Jan 29, 2009 5:57 pm

{11.13}Lobachevsky wrote:
{11.13}Lobachevsky wrote:
Maybe I've been using Dyalog APL too long, but it seems that something like a Dyalog namespace is what is needed to make this work well.
Suppose every primitive definition has its own namespace. #.WITHOUT, #.RANK and the main function or operator is named the same as the namespace
* Combine APL functions - no problem
* Global names: #.[]IO, #.GLOBAL, etc.
* Specify the symbol: #.WITHOUT.[]SYMBOL := '~' '[]WITHOUT'
* Previous meaning: Why do you really need this? Go into the namespace and make the old function a subroutine.

I always thought that STSC/Manugistics/APL2000's ]CMDS and Dyalogs namespaces would be a good marriage.
APLX has a lighter weight namespace-like object which is also worth looking at.


I like this idea. I can see I wasn't thinking generally enough.


Is there anywhere an overview of each of the various namespace implementations?

forummaster
 
Posts: 555
Joined: Wed Jan 23, 2013 1:00 pm

Re: Need Some Design Help

PostPosted by drab » Thu Oct 23, 2014 5:40 am

I have little knowledge or experience with any existing implementation of APL namespaces. But consider this ...

What about a new system command called import, with a syntax identical to copy:

)import there f

Then, with the syntax

there.f

you could locally use the function f residing in the saved workspace named there.

(Think "containing" when you read the dot in the compound name.)

⎕nl, ⎕nc,and ⎕cr could be made aware of all imported objects, if any.

To greatly increase flexibility, there could also be a new system function ⎕import that does the same thing as )import.

To get fancy, maybe ⎕nl and ⎕nc and maybe ⎕cr could be enhanced with a left argument character vector naming a saved workspace, so you could look at importable objects without importing them.

This idea could also cover the entire concept of magic defined functions, by using a special reserved named for the "saved workspace" in import.
drab
 
Posts: 295
Joined: Thu Oct 09, 2014 6:23 am

Re: Need Some Design Help

PostPosted by drab » Thu Oct 23, 2014 6:09 am

To undo an import, you could use )erase or ⎕ex .

Though that could certainly cause trouble if you erased a builtin magic function.

However, maybe you could also use the import facility to REPLACE a magic function, which might be really interesting.
drab
 
Posts: 295
Joined: Thu Oct 09, 2014 6:23 am


Return to Magic Functions

Who is online

Users browsing this forum: No registered users and 0 guests

cron