Reflect the set-default-attributes current situation.
[clinton/lisp-on-lines.git] / lisp-on-lines.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass article
4 \language english
5 \inputencoding auto
6 \fontscheme default
7 \graphics default
8 \paperfontsize default
9 \spacing single
10 \papersize a4paper
11 \paperpackage widemarginsa4
12 \use_geometry 0
13 \use_amsmath 0
14 \use_natbib 0
15 \use_numerical_citations 0
16 \paperorientation portrait
17 \secnumdepth 3
18 \tocdepth 3
19 \paragraph_separation indent
20 \defskip medskip
21 \quotes_language english
22 \quotes_times 2
23 \papercolumns 1
24 \papersides 1
25 \paperpagestyle default
26
27 \layout Title
28
29 LISP-ON-LINES
30 \layout Author
31
32
33 \noun on
34 Drew Crapmsie
35 \noun default
36 ,
37 \noun on
38 José Pablo Ezequiel
39 \begin_inset Quotes eld
40 \end_inset
41
42 Pupeno
43 \begin_inset Quotes erd
44 \end_inset
45
46 Fernández Silva
47 \layout Abstract
48
49
50 \noun on
51 Lisp-On-Lines
52 \noun default
53 is a very useful module that works on top of the
54 \noun on
55 UnCommon Web
56 \noun default
57 framework to do rapid developing of complex data-driven web appilcations
58 (on
59 \noun on
60 Common Lisp
61 \noun default
62 , of course).
63 \layout Section
64
65 Introduction
66 \layout Standard
67
68
69 \noun on
70 Lisp-On-Lines
71 \noun default
72 was founded and developed and continues to be developed and mantained by
73
74 \noun on
75 Drew Crapmsie
76 \noun default
77 .
78 \layout Subsection
79
80 Conventions
81 \layout Standard
82
83 The conventions used in this manual are:
84 \layout Itemize
85
86 Lisp code is shown as a monospace font.
87 It is assumed that the user is working in an interactive environment and
88 what the user should type appears as bold, for example:
89 \begin_deeper
90 \layout LyX-Code
91
92 >
93 \series bold
94 (+ 5 10)
95 \layout LyX-Code
96
97 15
98 \end_deeper
99 \layout Itemize
100
101 Names of people or products are show as small caps, like
102 \noun on
103 Drew Crapmsie
104 \noun default
105 or
106 \noun on
107 Lisp-On-Lines
108 \noun default
109 .
110 \layout Itemize
111
112 Sections marked with
113 \color red
114 ToDo
115 \color default
116 require further revision.
117 \layout Standard
118
119
120 \color red
121 ToDo: Add more conventions as they are needed, possible classes of text:
122 names of concepts, name of programming entities, like variables, functions,
123 etc (which are embedded in text, should they be shown monospaced ?).
124 \layout Section
125
126 Components
127 \layout Description
128
129 Meta\SpecialChar ~
130 Model\SpecialChar ~
131 Protocol A Protocol for introspection on relational objects.
132 \layout Description
133
134 Mewa\SpecialChar ~
135 Presentations A Mewa-like
136 \begin_inset Foot
137 collapsed true
138
139 \layout Standard
140
141 http://www.adrian-lienhard.ch/files/mewa.pdf
142 \end_inset
143
144 layer for UncommonWeb
145 \begin_inset Foot
146 collapsed true
147
148 \layout Standard
149
150 http://common-lisp.net/project/ucw/
151 \end_inset
152
153 Presentations.
154 \layout Section
155
156 Example
157 \layout Standard
158
159 First we start with the data model.
160 The Meta Model Protocol (MMP) is used to provide information on the data
161 objects and how they relate to one another.
162 Its is currently implemented as a layer over CLSQL
163 \begin_inset Foot
164 collapsed true
165
166 \layout Standard
167
168 http://clsql.b9.com/
169 \end_inset
170
171 , although support is planned for other backends (
172 \noun on
173 CLOS
174 \noun default
175 ,
176 \noun on
177 Elephant
178 \noun default
179 [4], whatever).
180 \layout Standard
181
182 The MMP shares its definition syntax with
183 \emph on
184 \noun on
185 CLSQL
186 \emph default
187 \noun default
188 's Object Oriented Data Definition Language (OODDL)
189 \begin_inset Foot
190 collapsed true
191
192 \layout Standard
193
194 http://clsql.b9.com/manual/ref-ooddl.html
195 \begin_inset Note
196 collapsed true
197
198 \layout Standard
199
200 Shouldn't this footnote be a bibliographical entry ? or something like that
201 ?
202 \end_inset
203
204
205 \end_inset
206
207 .
208 The macro to define view-classes is named DEF-VIEW-CLASS/META, and takes
209 the same arguments as DEF-VIEW-CLASS from CLSQL.
210 For the purposes of this simple example, we will only need two functions
211 from the MMP beyond what CLSQL provides : LIST-SLOTS and LIST-SLOT-TYPES[5].
212 \layout Standard
213
214 We'll define a simple class to hold a user.
215 \layout LyX-Code
216
217 >
218 \series bold
219 (def-view-class/meta user ()
220 \layout LyX-Code
221
222
223 \series bold
224 ((userid :initarg :userid :accessor userid :type integer :db-kind :key)
225 \layout LyX-Code
226
227
228 \series bold
229 (username :initarg :username :accessor username :type string :db-kind
230 :base)
231 \layout LyX-Code
232
233
234 \series bold
235 (password :initarg :password :accessor password :type string :db-kind
236 :base)))
237 \layout Standard
238
239 and now we create a user:
240 \layout LyX-Code
241
242 >
243 \series bold
244 (defparameter user (make-instance 'user :userid 1
245 \layout LyX-Code
246
247
248 \series bold
249 :username "drewc"
250 \layout LyX-Code
251
252
253 \series bold
254 :password "p@ssw0rd"))
255 \layout Standard
256
257 We can see the slots of users running:
258 \layout LyX-Code
259
260 >
261 \series bold
262 (lisp-on-lines::list-slots user)
263 \layout LyX-Code
264
265 (USERID USERNAME PASSWORD)
266 \layout Standard
267
268 or the types with:
269 \layout LyX-Code
270
271 >
272 \series bold
273 (lisp-on-lines::list-slot-types user)
274 \layout LyX-Code
275
276 ((USERID INTEGER) (USERNAME STRING) (PASSWORD STRING))
277 \layout Standard
278
279 To see the default attributes of a class
280 \begin_inset Marginal
281 collapsed true
282
283 \layout Standard
284
285 Is this correct ? Drew, please, check.
286 \end_inset
287
288 we run.
289 \layout LyX-Code
290
291 >
292 \series bold
293 (lisp-on-lines::default-attributes user)
294 \layout LyX-Code
295
296 ((USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
297 \layout LyX-Code
298
299 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
300 \layout LyX-Code
301
302 (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD))
303 \layout Standard
304
305 To set the attributes of a class to the default values we use:
306 \layout LyX-Code
307
308 >
309 \series bold
310 (lisp-on-lines::set-default-attributes user)
311 \layout LyX-Code
312
313 ((USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
314 \layout LyX-Code
315
316 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
317 \layout LyX-Code
318
319 (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD))
320 \layout Standard
321
322 which takes an object of the class we are working with.
323 This is going to be change so we can do this action directly on the class.
324 It is on the TODO file.
325 \layout Standard
326
327 Class attributes?
328 \layout LyX-Code
329
330 >
331 \series bold
332 (lisp-on-lines::find-class-attributes user)
333 \layout LyX-Code
334
335 (USER (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)
336 \layout LyX-Code
337
338 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
339 \layout LyX-Code
340
341 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
342 \layout LyX-Code
343
344 NIL)
345 \layout Standard
346
347 note that the mewa functions (find-attribute, set-attribute etc) can take
348 either an instance, or a class-name as a symbol:
349 \layout LyX-Code
350
351 >
352 \series bold
353 (lisp-on-lines::find-class-attributes 'user)
354 \layout LyX-Code
355
356 (USER (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)
357 \layout LyX-Code
358
359 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
360 \layout LyX-Code
361
362 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
363 \layout LyX-Code
364
365 NIL)
366 \layout LyX-Code
367
368 >
369 \series bold
370 (lisp-on-lines::find-class-attributes (make-instance 'user))
371 \layout LyX-Code
372
373 (USER (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)
374 \layout LyX-Code
375
376 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
377 \layout LyX-Code
378
379 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
380 \layout LyX-Code
381
382 NIL)
383 \layout Standard
384
385 Using that information, we have enough to create an interface to the object.
386
387 \noun on
388 UnCommon Web
389 \noun default
390 includes a powerful presentation system
391 \begin_inset Foot
392 collapsed true
393
394 \layout Standard
395
396 To see this system in action, we strongly recomend to study the presentations
397 example which comes with
398 \noun on
399 UnCommon Web
400 \noun default
401 .
402 Reading components/presentations.lisp can help understand a lot about how
403 presentations are built.
404 \end_inset
405
406 , but it is not dynamic enough for some of the most advanced applications.
407 Mewa defines an approach to presentations that solves that problem, but
408 the paper is written from a
409 \noun on
410 Smalltalk
411 \noun default
412 point of view.
413 A mixture of the two , Mewa Presentations(MP), is described here.
414 \layout Standard
415
416 MP introduces to
417 \noun on
418 UnCommon Web
419 \noun default
420 the concept of
421 \emph on
422 attributes
423 \emph default
424 .
425 An attribute is essentially a named version of the DEFPRESENTATION slot-like
426 arguments, for example in :
427 \layout LyX-Code
428
429 >
430 \series bold
431 (defpresentation person-editor (object-presentation)
432 \layout LyX-Code
433
434
435 \series bold
436 ((string :label "First Name" :slot-name 'first-name :max-length 30)))
437 \layout Standard
438
439 the (string :label "First Name" ...) form is an attribute definiton.
440 Attributes are accessed through FIND-ATTIRIBUTES, and are composed at run
441 time (where the
442 \noun on
443 UnCommon Web
444 \noun default
445 's presentation system is done at compile time) to display the object.
446 This allows a very flexible system of displaying objects which is reminiscent
447 of
448 \noun on
449 CSS
450 \noun default
451
452 \begin_inset Foot
453 collapsed true
454
455 \layout Standard
456
457
458 \noun on
459 Drew Crapmsie
460 \noun default
461 discovered this, rather than invent or design it, so there are some rough
462 edges, but its a good start.
463 \end_inset
464
465 .
466 \layout Standard
467
468 Its much easier to show this than to tell.
469 Lets present our user class.
470 Currently in
471 \noun on
472 UnCommon Web
473 \noun default
474 , you'd define a presentation as such :
475 \layout LyX-Code
476
477 >
478 \series bold
479 (defpresentation user-presentation (object-presentation)
480 \layout LyX-Code
481
482 ((INTEGER :LABEL "USERID" :SLOT-NAME USERID)
483 \layout LyX-Code
484
485 (STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
486 \layout LyX-Code
487
488 (STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)))
489 \layout Standard
490
491 which could be presented using PRESENT-OBJECT :
492 \layout LyX-Code
493
494 >
495 \series bold
496 (present-object user :using 'user-presentation)
497 \layout Standard
498
499 The equivalent approach using mewa presentations is actually longer and
500 more verbose(!) but it serves to demonstrate how the MP system works.
501 \layout Standard
502
503 Mewa Presentations adds a set of attributes to a class, keyed off the class
504 name.
505 Attributes are inherited, so if you define an attribute on T, you can use
506 it with any class.
507 \layout Standard
508
509 MP stores named attributes keyed on a class name.
510 To achieve the same functionality as the above using mp would look like
511 this :
512 \layout LyX-Code
513
514 >
515 \series bold
516 (setf (lisp-on-lines::find-attribute 'user :viewer)
517 \begin_inset Marginal
518 collapsed true
519
520 \layout Standard
521
522 Isn't this too imperative (in contrast to functional, lispy).
523 \end_inset
524
525
526 \layout LyX-Code
527
528
529 \series bold
530 '(lisp-on-lines::mewa-object-presentation
531 \layout LyX-Code
532
533
534 \series bold
535 :attributes (userid username password)
536 \layout LyX-Code
537
538
539 \series bold
540 :global-properties (:editablep nil)))
541 \layout LyX-Code
542
543 (:VIEWER MEWA-OBJECT-PRESENTATION
544 \layout LyX-Code
545
546 :ATTRIBUTES
547 \layout LyX-Code
548
549 (USERID USERNAME PASSWORD)
550 \layout LyX-Code
551
552 :GLOBAL-PROPERTIES
553 \layout LyX-Code
554
555 (:EDITABLEP NIL))
556 \layout LyX-Code
557
558 >
559 \series bold
560 (setf (lisp-on-lines::find-attribute 'user 'userid)
561 \begin_inset Marginal
562 collapsed true
563
564 \layout Standard
565
566 Are this setfs to 'userid, 'username and 'password needed ? I (Pupeno) inspected
567 they contents at of this moment and they seem to already contain what they
568 are being set to.
569 \end_inset
570
571
572 \layout LyX-Code
573
574
575 \series bold
576 '(integer :label "userid" :slot-name userid))
577 \layout LyX-Code
578
579 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
580 \layout LyX-Code
581
582 >
583 \series bold
584 (setf (lisp-on-lines::find-attribute 'user 'username)
585 \layout LyX-Code
586
587
588 \series bold
589 '(STRING :LABEL "USERNAME" :SLOT-NAME USERNAME))
590 \layout LyX-Code
591
592 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
593 \layout LyX-Code
594
595 >
596 \series bold
597 (setf (lisp-on-lines::find-attribute 'user 'password)
598 \layout LyX-Code
599
600
601 \series bold
602 '(STRING :LABEL "USERNAME" :SLOT-NAME PASSWORD))
603 \layout LyX-Code
604
605 (PASSWORD STRING :LABEL "USERNAME" :SLOT-NAME PASSWORD)
606 \layout LyX-Code
607
608 >
609 \series bold
610 (lisp-on-lines::find-class-attributes 'user)
611 \layout LyX-Code
612
613 (USER
614 \layout LyX-Code
615
616 (:VIEWER MEWA-OBJECT-PRESENTATION
617 \layout LyX-Code
618
619 :ATTRIBUTES
620 \layout LyX-Code
621
622 (USERID USERNAME PASSWORD)
623 \layout LyX-Code
624
625 :GLOBAL-PROPERTIES
626 \layout LyX-Code
627
628 (:EDITABLEP NIL))
629 \layout LyX-Code
630
631 (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)
632 \layout LyX-Code
633
634 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
635 \layout LyX-Code
636
637 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
638 \layout LyX-Code
639
640 NIL)
641 \layout Standard
642
643 this is all turned into a
644 \noun on
645 UnCommon Web
646 \noun default
647 presentation at runtime using MAKE-PRESENTATION, for example, the following
648 code should be enough to show what's built so far attached to the examples
649 application:
650 \layout LyX-Code
651
652 >
653 \series bold
654 (defcomponent lol-example (window-component)
655 \layout LyX-Code
656
657
658 \series bold
659 ())
660 \layout LyX-Code
661
662 >
663 \series bold
664 (defmethod render-on ((res response) (lol-example lol-example))
665 \layout LyX-Code
666
667
668 \series bold
669 (<:h1 "User")
670 \layout LyX-Code
671
672
673 \series bold
674 (<ucw:render-component :component (lisp-on-lines::make-presentation
675 user :type :viewer)))
676 \layout LyX-Code
677
678 >
679 \series bold
680 (defentry-point "lol.ucw" (:application *example-application*) ()
681 \layout LyX-Code
682
683
684 \series bold
685 (call 'products-presentation))
686 \layout Standard
687
688 As you'll see, nothing is exported from the LISP-ON-LINES package.
689 If you wish to use LOL in your own package (or in UCW-USER or whatever),
690 you simply need to use the MEWA and META-MODEL packages.
691 \layout Standard
692
693 SET-ATTRIBUTE can be used in place of (setf (find-attribute)) when you want
694 to "inherit" the properties of an existing attribute definition :
695 \layout Standard
696
697 LISP-ON-LINES> (set-attribute 'user 'password '(string :label "password:
698 (must be at leat 8 chars)"))
699 \layout Standard
700
701 (PASSWORD STRING
702 \layout Standard
703
704 :LABEL
705 \layout Standard
706
707 "password: (must be at leat 8 chars)"
708 \layout Standard
709
710 :SLOT-NAME
711 \layout Standard
712
713 PASSWORD)
714 \layout Standard
715
716 Now we want to create a presentation with which to edit the username.
717 we will use the existing attributes on a subclass of mewa-object-presetation
718 :
719 \layout Standard
720
721 LISP-ON-LINES> (defcomponent user-editor (mewa-object-presentation)
722 \layout Standard
723
724 ()
725 \layout Standard
726
727 (:default-initargs
728 \layout Standard
729
730 :attributes '((username :label "Enter your New Username") password)
731 \layout Standard
732
733 :global-properties '(:editablep t)))
734 \layout Standard
735
736 USER-EDITOR
737 \layout Standard
738
739 LISP-ON-LINES> (setf (find-attribute 'user :editor) '(user-editor))
740 \layout Standard
741
742 (:EDITOR USER-EDITOR)
743 \layout Standard
744
745 LISP-ON-LINES>
746 \layout Standard
747
748 which we then can display below our earlier example :
749 \layout Standard
750
751 (defmethod render-on ((res response) (e presentations-index))
752 \layout Standard
753
754 "
755 \layout Standard
756
757 As you'll see, nothing is exported from the LISP-ON-LINES package.
758
759 \layout Standard
760
761 if you wish to use LOL in your own package (or in UCW-USER or whatever),
762 \layout Standard
763
764 you simply need to use the MEWA and META-MODEL packages"
765 \layout Standard
766
767 (<ucw:render-component :component (lisp-on-lines::make-presentation lisp-on-line
768 s::user :type :viewer))
769 \layout Standard
770
771 (<ucw:render-component :component (lisp-on-lines::make-presentation lisp-on-line
772 s::user :type :editor)))
773 \layout Standard
774
775 that should give you some idea on how it works ..
776 ask me when you get confused :)
777 \the_end