Skip to content

Instantly share code, notes, and snippets.

@gcentauri
Created August 31, 2019 19:54
Show Gist options
  • Save gcentauri/cf28da3988ae2d53937ca69c79d3b1de to your computer and use it in GitHub Desktop.
Save gcentauri/cf28da3988ae2d53937ca69c79d3b1de to your computer and use it in GitHub Desktop.
reworked picolisp guestbook example
(load "@lib/http.l" "@lib/xhtml.l" "@lib/form.l")
# in a real application you would use 'allowed to restrict access to
# certain directories and functions.
# you would also put httpGate, nginx or somesuch between the Internet
# and the port where your program is listening.
(class +Msg +Entity)
(rel hdr (+String))
(rel bdy (+String))
(rel sdr (+String))
(rel dor (+String))
(rel book (+Joint) msgs (+Gbk))
# here a TODO could be to write a method that outputs message contents
(class +Gbk +Entity)
(rel nm (+Ref +String))
(rel msgs (+List +Joint) book (+Msg))
(dm addM> (Hdr Bdy Sdr)
(let D (new! '(+Msg)
'hdr Hdr
'bdy Bdy
'sdr Sdr
'dor (stamp)
'book This )
(put!> This 'msgs D) ) )
(de work ()
(app) # sets up session handling
(action # says there will be action in some web forms
(html 0 *Gbk "@lib.css" NIL
(<h2> NIL *Gbk)
(<hr>)
(form NIL
(<p> NIL "Message header:")
(gui 'hdr '(+Var +TextField) '*MsgHdr 30)
(do 2 (<br>))
(<p> NIL "Message text:")
(gui 'bdy '(+Var +TextField) '*MsgBdy 30 5)
(do 2 (<br>))
(<p> NIL "Your name:")
(gui 'sdr '(+Var +TextField) '*MsgSdr 30)
(do 2 (<br>))
(gui '(+Button) "Send"
'(ask "Post this message?"
(addM> (db 'nm '+Gbk *Gbk) *MsgHdr *MsgBdy *MsgSdr) ) ) )
(<br>)
(<hr>)
(for X (get (db 'nm '+Gbk *Gbk) 'msgs) # instead of '+Chart, '+QueryChart or 'url>
(with X
(<h3> NIL (ht:Prin (: hdr)) )
(<br>)
(<p> NIL (ht:Prin (: bdy)) )
(<br>)
(<p> NIL (ht:Prin (pack (: sdr) " - " (: dor))) )
(<br>) ) ) ) ) )
(de main ()
(pool "gb.db")
## if *DB is empty, initialize with your Fancy Guestbook
(unless (seq *DB)
(new! '(+Gbk) 'nm "Fancy Guestbook") )
## you only have one guestbook, store its name to look it up in the DB
(setq *Gbk "Fancy Guestbook") ) # just using a global *Gbk to hold the name
(de go ()
(server 8080 "!work") )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment