cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
hogi
Level XII

List of Strings

To create a matrix of N identical numbers, I can use J(N, 1, number).

What is the shortest (syntax) and fastest way to create a list of N identical strings?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: List of Strings

Repeat({"A"}, 1000)
-Jarmo

View solution in original post

7 REPLIES 7
jthi
Super User

Re: List of Strings

Repeat({"A"}, 1000)
-Jarmo
hogi
Level XII

Re: List of Strings

: )

Scripting Index -> Online Help -> Scripting Guide:
https://www.jmp.com/support/help/en/18.0/#page/jmp/repeat-function.shtml#ww270242 

 

hogi_1-1729246548568.png


I fear a LLM will have its difficulties with such cool hidden features ...

jthi
Super User

Re: List of Strings

I'm not really sure if there is anything hidden about Repeat()? Of course, you have to know about it, but you will come across it fairly quickly in scripting index. But you might need a bit of luck as the function group which it belongs to is Character and not Character, Matrix and List which it should be but it isn't the only one like this.

 

You can also go with a bit more "normal" route where replace all values in a list

 

Names Default To Here(1);

l = As List(J(1000, 1, .));

l[1::N Items(l)] = "A";

show(l);

 

 

-Jarmo
hogi
Level XII

Re: List of Strings

It's easy to find Repeat, but it's more difficult to find and understand the correct syntax to generate the list.

hogi_1-1729320765729.png

 

hogi_3-1729320842146.png

 

hogi_0-1729320706687.png

 

jthi
Super User

Re: List of Strings

Both scripting index and Scripting Guide provide an example for that

jthi_0-1729343016746.png

jthi_1-1729343030636.png

Function description also tells quite accurately what Repeat() does but it does require some extra understanding on how concatenation of lists in JMP works. Luckily JSL Syntax Reference at least offers link to Scripting Guide which has much better documentation of the function

jthi_2-1729343070562.png

 

Also one more method is to use Substitute (Repeat() is what I would use in simple case like this)

Names Default To Here(1);

l = Substitute(As List(J(1000, 1, 1)), 1, "A");
-Jarmo
hogi
Level XII

Re: List of Strings

Yes, see https://community.jmp.com/t5/Discussions/List-of-Strings/m-p/806737/highlight/true#M98527 
I agree, it's very well described in the Scripting Guide. Interesting that the LLM did not find / use (?)  this information.

From the Scripting Index and the JSL syntax reference it's not possible to get this detail.

[Scripting Index: ... without executing the code - and interpreting the result].

Some comments / details will help the users - and the LLM.

Once the documentation can be found and understood by a LLM, JSL coding will be like heaven : )

jthi
Super User

Re: List of Strings

Scripting Index and JSL Syntax reference both do contain this information?

  • Scripting Index
    • Returns the text, matrix, or list specified by the x argument concatenated with itself n times.

  • JSL Syntax Reference
    • Returns a copy of source concatenated with itself a times

You might have to read it a bit in reverse, as you might not (initially) consider your input as a list but your output is. You also might have to take a look into list concatenation Character Functions (jmp.com) (once again should be also found under list and matrix)

 

Also one more option for simple cases is to utilize Repeat with a string and then use Words to break it into a list

 

Names Default To Here(1);

l = Words(Repeat("A", 1000), "");

 

 

-Jarmo