Size: 1038
Comment:
|
Size: 1887
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
We can write a simple function to create HTML and pass that to a browser. | = Creating a simple HTML page using APL = We can write a simple function to create HTML and pass that to a browser in order to display our Hello World example. Here's the function in Dyalog APL: |
Line 11: | Line 15: |
}}} | |
Line 13: | Line 16: |
{{{ | |
Line 21: | Line 23: |
Below is the output HTML from the above function. | And here's the same thing in APLX. (This code should also work in APL+Win). {{{ ∇R←tagname tag contents [1] :If 0=⎕nc 'tagname' [2] tagname←'p' ⍝ Left argument defaults to 'p' for paragraph [3] :EndIf [4] R←'<',tagname,'>',contents,'</',tagname,'>' ∇ ∇CreateHtml;htmlCode;body;head [1] body←'body' tag('h1' tag '"Hello World with APL in HTML'),('h2' tag 'hello ...'),tag '...world' [2] head←'head' tag('title' tag 'Hello world with APL'),('' tag '') [3] htmlCode←'html' tag head,body [4] 'helloworld.html' ⎕NCREATE 1 ⋄ htmlCode ⎕NWRITE 1 ⋄ ⎕NUNTIE 1 ∇ }}} Below is the output HTML from the above function (Both Dyalog and APLX functions produce the same): |
Line 36: | Line 58: |
attachment:helloworldhtml.jpg | {{attachment:helloworldhtml.jpg}} |
Line 40: | Line 62: |
CategoryHelloWorld CategoryDyalog | CategoryHelloWorld CategoryDyalog CategoryAplx |
Creating a simple HTML page using APL
We can write a simple function to create HTML and pass that to a browser in order to display our Hello World example.
Here's the function in Dyalog APL:
tag←{ ⍺←'p' 0∊⍴⍵:'' (tg style)←{⎕ML←1 ' '∊⍵:⍵{(⍵↑⍺)(⍵↓⍺)}¯1+⍵⍳' ' ⍵''}⍺ '<',tg,style,'>',(('<'=1⍴⍵)/nl),⍵,'</',tg,'>',nl } ∇ CreateHtml;htmlCode;body;head [1] body←'body'tag('h1'tag'"Hello World with APL in HTML'),('h2'tag'hello...'),tag'...world' [2] head←'head'tag('title'tag'Hello world with APL'),(''tag'') [3] htmlCode←'html'tag head,body [4] htmlCode{(⎕NUNTIE ⍵){}⍺ ⎕NAPPEND ⍵}'helloworld.html'⎕NCREATE 0 ∇
And here's the same thing in APLX. (This code should also work in APL+Win).
∇R←tagname tag contents [1] :If 0=⎕nc 'tagname' [2] tagname←'p' ⍝ Left argument defaults to 'p' for paragraph [3] :EndIf [4] R←'<',tagname,'>',contents,'</',tagname,'>' ∇ ∇CreateHtml;htmlCode;body;head [1] body←'body' tag('h1' tag '"Hello World with APL in HTML'),('h2' tag 'hello ...'),tag '...world' [2] head←'head' tag('title' tag 'Hello world with APL'),('' tag '') [3] htmlCode←'html' tag head,body [4] 'helloworld.html' ⎕NCREATE 1 ⋄ htmlCode ⎕NWRITE 1 ⋄ ⎕NUNTIE 1 ∇
Below is the output HTML from the above function (Both Dyalog and APLX functions produce the same):
<html> <head> <title>Hello world with APL</title> </head> <body> <h1>"Hello World with APL in HTML</h1> <h2>hello...</h2> <p>...world</p> </body> </html>
And here is what a browser makes of it.
Page created by Phil Last at 2008-02-26