An entertaining use of del
2 posts
• Page 1 of 1
An entertaining use of del
So late last night in an attempt to come up with a quick and dirty object-oriented framework for building up HTML, I wrote this:
I particularly enjoyed line 7:
I have not seen this use of del anywhere in the dfns namespace that I could find.
This little dfn lets me write:
Which then can be turned into HTML with an appropriately coded render function:
- Code: Select all
Add←{
⍺←⎕THIS
e t←(2=≡⍵)⊃(⍵'')⍵
e≡'':⍺⊣⍺.Content,←⊂t
s←⎕NS''
s.Element←e
s.Content←(0=⍴t)⊃(,⊂t)t
s.Add←∇
0=⍺.⎕NC'Content':s
⍺.Content,←s
s
}
I particularly enjoyed line 7:
s.Add←∇
I have not seen this use of del anywhere in the dfns namespace that I could find.
This little dfn lets me write:
h←Add 'html'
b←h.Add 'body'
h1←b.Add 'h1' 'My Heading'
h1.class←'MyClass'
h1.id←'MyID'
Which then can be turned into HTML with an appropriately coded render function:
Render h
<html><body><h1 class="MyClass" id="MyID">My Heading</h1></body></
html>
- paulmansour
- Posts: 420
- Joined: Fri Oct 03, 2008 4:14 pm
Re: An entertaining use of del
Very nice!
-
StefanoLanzavecchia - Posts: 109
- Joined: Fri Oct 03, 2008 9:37 am
2 posts
• Page 1 of 1
Return to Functional Programming
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group