Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

scheming anything/anytype - creating base types experiment

Submitted by vlado on Tue, 2006-02-14 12:18.code | scheme | work in progress

This is an experiment to some 'atomic' types in scheme. It was tested only in plt scheme.

The basic idea is that we need some 'atomic' types, from wich to construct everything else in a web cms - users, content nodes, etc... The base field types defined here are - text, stext (short text), date, integer and float.Each field type is a closure, in which some properties, getters, setters and type-checkers are defined.

To define a new field type use the make/any/type macro. In the second part of this code snippet you will find a series of type definitions and helper functions. I quite like how this looks in scheme. I'm surprised actually. This ended up as a very cute OO-like code.

You may find that some of the procedures are not using the typical ...? meaning. Although the purely functional version, i.e without the setters is sufficient, they provide some extra flexibility, and possibly can help reduce memory consumption.

;helper to create uniform field types (define make/any/type/field (lambda (f) (let [(data f)] (lambda (op arg) (cond ( (eq? '! op) (set! data arg) ) ( (eq? '<< op) data )))))) ;the syntax of a any/type (define-syntax make/any/type (syntax-rules() ((_ t) (lambda (id name data delta required format) (let* ( (id (make/any/type/field id)) (name (make/any/type/field name)) (data (make/any/type/field data)) (delta (make/any/type/field delta)) (required (make/any/type/field required)) (format (make/any/type/field format)) (type t)) (lambda(op . rest) (cond ( (eq? op '?) (eq? (car rest) type)) ( (eq? op 'type) type) ( (eq? op 'id) (id '<< '())) ( (eq? op 'name) (name '<< '())) ( (eq? op 'data) (data '<< '())) ( (eq? op 'delta) (delta '<< '() )) ( (eq? op 'required) (required '<< '())) ( (eq? op 'format) (format '<< '())) ;-- ( (eq? op 'id!) (id '! (car rest))) ( (eq? op 'name!) (name '! (car rest))) ( (eq? op 'data!) (data '! (car rest))) ( (eq? op 'delta!) (delta '! (car rest))) ( (eq? op 'required!) (required '! (car rest))) ( (eq? op 'format!) (format '! (car rest))))))))))

Here come the predefined atomic field types - they are atomic for the toy cms ;predefined any/types ;any/text - text ;any/stext - short text ;any/int - integer ;any/float - float ;any/date - date (define make-any/text (make/any/type 'any/text)) (define (any/text? x) (x '? 'any/text)) (define make-any/stext (make/any/type 'any/stext)) (define (any/stext? x) (x '? 'any/stext)) (define make-any/int (make/any/type 'any/int)) (define (any/int? x) (x '? 'any/int)) (define make-any/float (make/any/type 'any/float)) (define (any/float? x) (x '? 'any/float)) (define make-any/date (make/any/type 'any/date)) (define (any/date? x) (x '? 'any/date)) ;========================================= (define (type? x) (x 'type)) (define (id? x) (x 'id)) (define (name? x) (x 'name)) (define (data? x) (x 'data)) (define (delta? x) (x 'delta)) (define (required? x) (x 'required)) (define (format? x) (x 'format)) ;========================================= (define (id! x y) (x 'id! y)) (define (name! x y) (x 'name! y)) (define (data! x y) (x 'data! y)) (define (delta! x y) (x 'delta! y)) (define (required! x y) (x 'required! y)) (define (format! x y) (x 'format! y)) ;========================================= (define ( x y) (> (x 'delta) (y 'delta) )) (define (delta= x y) (equal? (x 'delta) (y 'delta) ))

A bit later I'll post the relevant sql interface

read more | vlado's blog | add new comment

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <br /> <br> <div> <a> <em> <strong> <cite> <pre> <code> <ul> <ol> <li> <dl> <dt> <dd> <h3> <img> <blockquote> <q> <strike> <small> <h4> <h5> <h6>
  • Link to content with [[some text]], where "some text" is the title of existing content or the title of a new piece of content to create. You can also link text to a different title by using [[link to this title|show this text]]. Link to outside URLs with [[http://www.example.com|some text]], or even [[http://www.example.com]].
  • Lines and paragraphs break automatically.
More information about formatting options
Home ยป scheming anything/anytype - creating base types experiment

dikini.net

spreading confusion by accident since 1970