Assign a variable over multiple lines in Class editor

Writing and using Classes in Dyalog APL

Assign a variable over multiple lines in Class editor

Postby bilekflo on Wed Jul 13, 2022 8:15 am

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
bilekflo
 
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Re: Assign a variable over multiple lines in Class editor

Postby yaemmanuelli on Wed Jul 13, 2022 1:58 pm

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
User avatar
yaemmanuelli
 
Posts: 16
Joined: Sat Aug 01, 2020 6:29 pm
Location: Recloses, France

Re: Assign a variable over multiple lines in Class editor

Postby bilekflo on Fri Jul 15, 2022 8:13 am

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
bilekflo
 
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Re: Assign a variable over multiple lines in Class editor

Postby Adam|Dyalog on Sat Jul 16, 2022 11:30 pm

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
User avatar
Adam|Dyalog
 
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Assign a variable over multiple lines in Class editor

Postby bilekflo on Mon Jul 18, 2022 5:33 am

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
bilekflo
 
Posts: 28
Joined: Wed Mar 12, 2014 10:07 pm

Re: Assign a variable over multiple lines in Class editor

Postby Adam|Dyalog on Mon Jul 18, 2022 6:04 am

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.)
User avatar
Adam|Dyalog
 
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Assign a variable over multiple lines in Class editor

Postby Josh|Dyalog on Wed Jul 20, 2022 2:08 am

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
Josh|Dyalog
 
Posts: 2
Joined: Tue Jun 25, 2019 8:25 am


Return to Object Oriented Programming

Who is online

Users browsing this forum: Google [Bot] and 1 guest