I was browsing http://www.jsoftware.com/jwiki/Literate and became motivated
to start working on a basic implementation of the Workbook concept

The terseness of J is a good fit for an embedded language in a larger text
document or report (along the lines of ipython notebook) or rmarkdown.

I envision a web page that allows a document to be rendered that includes a
markup like:

{{{
NB. commands to set up the document
load 'data.ijs'
loadData''
}}}
# Summary
There are {{ # Customers }} customers and {{ # Orders }} orders. The most
recent order was {{ {. Order }}

# Top Customers
{{ renderTable 10 { Customers }}

Here is the start of my implementation. I welcome any feedback on it.

require 'regex'
PATTERN =.  '\{\{.*?\}\}'
SUBPATTERN =.  '\{\{(.*?)\}\}'
parse =. 3 : 0
 matches =. PATTERN rxmatches y
 ret =. matches rxcut y
 ( 0 ~: > # each ret ) # ret
)
eval =. 3 : 0
m=.SUBPATTERN rxmatches y
 if. 0 = # m  do.
  y
 else.
  ret =. {. ": ". > 1{"1 ( m rxfrom y)
 end.
)

template =: 3 : 0
ret=. eval each parse y
 ; ( 0 ~: > # each ret ) # ret
)

tests=: 3 : 0
assert. '1+1 is 2' -: template '1+1 is {{1+1}}'
assert. 'hello joe' -: template 'hello {{''''[a=:''joe''}}{{a}}'
a=:i.10
assert. 'the first number is 0' -: template 'the first number is {{{. a}}'
assert. 'the tail number is 9' -: template 'the tail number is {{{: a}}'
people=: 'bob';'frank'
tmpl=:template 'the people are {{}: }: ; (],&'', '') each ''Mr. ''&, each
people }}'
assert. 'the people are Mr. bob, Mr. frank' -: tmpl
)
tests''


After more searching, it has some overlap with JHP (
http://www.jsoftware.com/wsvn/addons/trunk/web/jhp/?#a76117735fae0ef49b3a78a3c9520a2c9).
 My template implementation might be more straightforward to use
standalone. In any event, more choices the better.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to