Python is a language that uses whitespace to basically emulate lisp
S-expressions but without using parentheses. The advantage is less error prone
typing. Here is some sample input, and the output I'd like to make.
test =: 0 : 0
html
head
body
p stuff
p div='adiv'
more stuff
table
tr
td 1
td 2
p last stuff
)
t =: ,. <"1@:(": ;. _2) test
+---------------+
|html |
+---------------+
| head |
+---------------+
| body |
+---------------+
| p stuff |
+---------------+
| p div='adiv'|
+---------------+
| more stuff |
+---------------+
| table |
+---------------+
| tr |
+---------------+
| td 1 |
+---------------+
| td 2 |
+---------------+
| p last stuff|
+---------------+
NB. Count of leading white space in each line above
whitespaces =: 0 1 2 3 3 4 3 4 5 5 3
NB. Verbs I used to determine whitespace (probably not needed for solution)
splitindex =: 1 : '(u y) & > i. #y'
truefalsesplit =: 4 : '(x # y) ; (-. x) # y'
leadwhite =: (truefalsesplit~ (] i. 2:) splitindex @: ((TAB, ' ')&i.))
#@:>@:{. S:1 leadwhite each <"1@:ArrayMaker test NB. results in whitespaces
above.
Desired Output
]sample=: (0{t),< (1{t),< (2{t) ,<( 3{t), (< ( (4{t) ,<5{t )) , (<( 6{t), ( <
(7{t),< ( (8{t), 9 {t))), 10{t
NB. (Run above line to get desired output tree: Too messy for email)
Can you make a function f such that whitespaces f t matches the above sample?
thank you.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm