Page 1 of 1

Assign a variable over multiple lines in Class editor

Posted: Wed Jul 13, 2022 8:15 am
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

Re: Assign a variable over multiple lines in Class editor

Posted: Wed Jul 13, 2022 1:58 pm
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

Re: Assign a variable over multiple lines in Class editor

Posted: Fri Jul 15, 2022 8:13 am
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

Re: Assign a variable over multiple lines in Class editor

Posted: Sat Jul 16, 2022 11:30 pm
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

Re: Assign a variable over multiple lines in Class editor

Posted: Mon Jul 18, 2022 5:33 am
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

Re: Assign a variable over multiple lines in Class editor

Posted: Mon Jul 18, 2022 6:04 am
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.)

Re: Assign a variable over multiple lines in Class editor

Posted: Wed Jul 20, 2022 2:08 am
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