Assign a variable over multiple lines in Class editor

Writing and using Classes in Dyalog APL
Post Reply
bilekflo
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Assign a variable over multiple lines in Class editor

Post by bilekflo »

Hi all,

I am using Dyalog version 18.2 and would like to assign a variable in multiple line notation.
Wanted to define a MsgText vector with each element is a message.

∇ SubInitMsgs ⍝ Setup Messages
MsgText←('Document Name saved.',
'Testmessage.' )


This does not work. What is here the trick?

Kind regards,
Florian
User avatar
yaemmanuelli
Posts: 16
Joined: Sat Aug 01, 2020 6:29 pm
Location: Recloses, France
Contact:

Re: Assign a variable over multiple lines in Class editor

Post by yaemmanuelli »

Hello,
For this purpose, I'd write using the APL Editor :
In the session, type :
Text←''
Then double click en Text to open the editor, and write your lines.
After closing the editor and saving the data you can display your text :
Text
Message Name saved.
Test message
Other message

If you want your text to be a vector of vectors (one line per subvector) :
]Box on
Was OFF
(Text≠⎕TC[3])⊆Text
┌───────────────────┬────────────┬─────────────┐
│Message Name saved.│Test message│Other message│
└───────────────────┴────────────┴─────────────┘

Hope this helps :-)
Regards
--
Yves-Antoine Emmanuelli
--
Yves-Antoine Emmanuelli
bilekflo
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Re: Assign a variable over multiple lines in Class editor

Post by bilekflo »

Hi Yves-Antoine,

Thank you for you input.
But how to do this in the editor? When I push ENTER is jumps to the next line.
I thought it would accept e.g. x←[ for a matrix or x←( for a vector entered over multiple lines.

BR Florian
User avatar
Adam|Dyalog
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Assign a variable over multiple lines in Class editor

Post by Adam|Dyalog »

bilekflo wrote:I thought it would accept e.g. x←[ for a matrix or x←( for a vector entered over multiple lines.

This is part of the novel APL Array Notation, which so far only exists as a model, not as a built-in part of the language. In version 18.2, you can use the model by wrapping your array in a dfn followed by "⎕SE.Dyalog.Array.Inline⍬"

E.g. you can define your MsgText as follows:
      MsgText←{('Document Name saved.'
'Testmessage.')}⎕SE.Dyalog.Array.Inline⍬

Not that there should be no "," at the end of any line.

If you wish to use this in the interactive session, enable experimental multiline input:
  • Under Windows: Options>Configure…>Session>Extended multiline input
  • Under all other platforms, set the configuration parameter (e.g. as an environmentvariable) DYALOG_LINEEDITOR_MODE=1

Aside: You can directly instruct the built-in editor about which type of text array you want:
  • For a simple character vector: )ed →Text
  • For a vector of character vectors: )ed ∊Text
  • For a character matrix: )ed -Text
bilekflo
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Re: Assign a variable over multiple lines in Class editor

Post by bilekflo »

Hi Adam,

Thanks for clarification. I thought this would be available already in 18.2 of Dyalog. The ⎕SE.Dyalog.Array.Inline⍬ can be used in the editor as well or in the interactive session only because I need it as part of a traditional function in a class.

Kind regards,
Florian
User avatar
Adam|Dyalog
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Assign a variable over multiple lines in Class editor

Post by Adam|Dyalog »

Yes, you can use this in traditional functions (inside or outside classes and namespaces, as well as in dfns) without even enabling the experimental multiline input.

(I've edited my post to make this a bit more clear.)
Josh|Dyalog
Posts: 2
Joined: Tue Jun 25, 2019 8:25 am

Re: Assign a variable over multiple lines in Class editor

Post by Josh|Dyalog »

A simpler approach worth mentioning is to use the traditional ,← idiom:

Code: Select all

      msg ← 'Document name saved.'
      msg,← 'Test message.'
      msg
Document name saved.Test message.
      ⍴msg
33
      msg ←⊂'Document name saved.'
      msg,←⊂'Test message.'
      msg
┌────────────────────┬─────────────┐
│Document name saved.│Test message.│
└────────────────────┴─────────────┘
      ⍴msg
2
Post Reply