more concise expression

72 views
Skip to first unread message

Sanju Dutt

unread,
Mar 7, 2026, 3:27:52 AMMar 7
to fo...@jsoftware.com
The task is to separate a given string into consonants and vowels.
Here is a solution:
str=:'chemistry'

sep_cons_vow=:((#~ 0=e.&'aeiou') str);((#~ 1=e.&'aeiou')str)


How can this be made more concise?




Marcin Żołek

unread,
Mar 7, 2026, 5:40:19 AMMar 7
to fo...@jsoftware.com
Using the adverb /. and hook can make the partitioning more concise.

Spoiler: https://jsoftware.github.io/juno/app/?c1=%28%3C%2F.~%20e.%26%27aeiouy%27%29%20%27chemistry%27

Cheers,
Marcin

Jan-Pieter Jacobs

unread,
Mar 7, 2026, 10:18:19 AMMar 7
to fo...@jsoftware.com
Note that Marcin's solution loses the ordering, i.e. it keeps the ordering of what occurs in y: If applied to 'abacus', vowels would be in the first box, and consonants in the second, opposite to when applied to 'chemistry', for instance. Also, if only vowels are present, only one box will result (e.g. 'io').

You can deal with these problems by prepending 'ab' to whatever argument you get to force vowels to be put in the first box, and behead the prepended example before boxing.
Otherwise, you could also combine the 0= and 1= into one:
  (<@#~ 0 1 =/ e.&'aeiou'@]) str
Even more concise could be to use set difference and intersection:
'aeiou' (-.~;[-.-.) str

Best regards,
Jan-Pieter

To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.

Jimmy Gauvin

unread,
Mar 19, 2026, 8:07:19 PM (8 days ago) Mar 19
to fo...@jsoftware.com
Hi all,

I was trying to remember how to use forks and hooks and stumbled onto this while trying various combinations :

str (-.^:2 ; -.) 'aeiou'


is there a way to simplify this even more ?


Jimmy


Sanju Dutt

unread,
Mar 20, 2026, 2:13:02 AM (7 days ago) Mar 20
to fo...@jsoftware.com
Try this:  'heliosphere'(-.^:0 1)'aeiou'

Regards,
Sanju 

David Lambert

unread,
Mar 20, 2026, 5:38:24 AM (7 days ago) Mar 20
to fo...@jsoftware.com
   NB. x and y are sets; result is intersection, in the order given in x
   setintersect =: e. # [
   separate1=:-.^:2;-.NB.original evaluates less thrice 
   separate2=: [ (-. ; ]) -. NB. evaluates less twice
   separate3=: setintersect ; -. NB. clear intent?

Jimmy Gauvin <jimmy....@gmail.com>: Mar 19 08:07PM -0400

Jan-Pieter Jacobs

unread,
Mar 20, 2026, 9:32:25 AM (7 days ago) Mar 20
to fo...@jsoftware.com
Interesting.
Combining both branches in one call to power calls -. only twice, reusing the first call:

    less =: {{x-.y[echo'less ran'}}
    'elephant' less^:1 2 'aeiou'
less ran
less ran
lphnt
eea  

Though, I noticed -.^:2 will supported by Special Combinations [0] so I don't know whether counts of theoretical invocations will still matter...

[0]:https://code.jsoftware.com/mediawiki/index.php?title=Vocabulary%2FSpecialCombinations&diff=59562&oldid=59084


Jan-Pieter


To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.

Henry Rich

unread,
Mar 20, 2026, 12:12:08 PM (7 days ago) Mar 20
to forum
Even with support for -.^:2 the power version would be about the same. 

I expect best is to do e. once and then # twice. 

Henry Rich

Raul Miller

unread,
Mar 20, 2026, 6:54:53 PM (7 days ago) Mar 20
to fo...@jsoftware.com
Or, rather

'heliosphere'(-.^:1 2)'aeiou'
hlsphr
eioee

Though the padding vs boxing issue would need to be acceptable,
wherever this was used.

--
Raul
Reply all
Reply to author
Forward
0 new messages