Dfn to/from TradFn converter
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 !
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 !
3 posts
• Page 1 of 1
Dfn to/from TradFn converter
Does anybody have a Dfn to TradFn converter kicking around, or
a TradFn to Dfn converter?
Thanks,
Bob
a TradFn to Dfn converter?
Thanks,
Bob
- rbe
- Posts: 9
- Joined: Fri Apr 13, 2018 7:55 pm
Re: Dfn to/from TradFn converter
Hi Bob,
May I ask what you need this for?
For example, I have sometimes wanted to exposed a dfn as a public method in a class, but dfn syntax does not allow :Access Public statements. However, it is easy to "wrap" a dfn in a tradfn to achieve this:
While I don't have a program to do it, conversion for dfn to tradfn is not too complicated. If I got it all right, it is:
May I ask what you need this for?
For example, I have sometimes wanted to exposed a dfn as a public method in a class, but dfn syntax does not allow :Access Public statements. However, it is easy to "wrap" a dfn in a tradfn to achieve this:
z←x Tradfn y
:Access Public
z←x{
Dfn
}y
While I don't have a program to do it, conversion for dfn to tradfn is not too complicated. If I got it all right, it is:
- Create the header: Fn←{ becomes z←{x} Fn y
- Replace argument names ⍺ and ⍵ with x and y
- Handle missing left arguments if necessary: ⍺←def becomes :If 900⌶⍬ ⋄ x←def ⋄ :EndIf
- Convert guards: cond:res becomes :If cond ⋄ z←res ⋄ :Return ⋄ :EndIf
- Convert error guards: errno::res becomes :Trap errno ⋄ rest of code ⋄ :Else ⋄ z←res ⋄ :EndTrap
- If desired, break out inner dfns into external sub-functions, but watch out for scoping rules!
- Insert z← on the last code line
-
Adam|Dyalog - Posts: 135
- Joined: Thu Jun 25, 2015 1:13 pm
Re: Dfn to/from TradFn converter
Hi, Adam,
As written, the APEX compiler handled TradFns only. Dfns came along
a wee bit later, and Dyalog did not have a CRAY distribution, so it
was not of great interest to me at the time, as the CRAYs were my
major target systems.
I am currently dealing with a small application that is written
in Dfns, so to compile it, I have two choices: Modify APEX to
support Dfns directly, or modify the incoming source functions to
turn them into Dfns. I took the latter approach because I have
an aversion to even looking at syntax analyzers. It is not
the direction would go in were I designing APEX now, of course.
I have the converter mostly working now, and will leave the boring
parts as ISMOP. Your overview for conversion left out, as all good
specifications do, things like: How do I detect where I have to
insert "z←" in lines of source code? [I cheat here, because I can.]
How do I handle nested Dfns: Note that I have to change ⍺ and ⍵ to
alpha and omega (What is the rationale for Dyalog not supporting
⍺ and ⍵ in TradFns?) BUT, I have to be careful about changing them
in nested Dfns, and probably do not want to change ⎕←'Is this an ⍺?'.
At any rate, I'll make the converter open source when I have a bit
of time in the next few weeks.
Thanks,
Bob
As written, the APEX compiler handled TradFns only. Dfns came along
a wee bit later, and Dyalog did not have a CRAY distribution, so it
was not of great interest to me at the time, as the CRAYs were my
major target systems.
I am currently dealing with a small application that is written
in Dfns, so to compile it, I have two choices: Modify APEX to
support Dfns directly, or modify the incoming source functions to
turn them into Dfns. I took the latter approach because I have
an aversion to even looking at syntax analyzers. It is not
the direction would go in were I designing APEX now, of course.
I have the converter mostly working now, and will leave the boring
parts as ISMOP. Your overview for conversion left out, as all good
specifications do, things like: How do I detect where I have to
insert "z←" in lines of source code? [I cheat here, because I can.]
How do I handle nested Dfns: Note that I have to change ⍺ and ⍵ to
alpha and omega (What is the rationale for Dyalog not supporting
⍺ and ⍵ in TradFns?) BUT, I have to be careful about changing them
in nested Dfns, and probably do not want to change ⎕←'Is this an ⍺?'.
At any rate, I'll make the converter open source when I have a bit
of time in the next few weeks.
Thanks,
Bob
- rbe
- Posts: 9
- Joined: Fri Apr 13, 2018 7:55 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group