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

Similar things

  • a sample testsuite for the (any/type) base types
  • Relations API - query generation and TODO
  • relations update
  • minor improvements
  • Learning lessons from Lisp or patterns and languages in PHP
  • Emulating closures in PHP
  • Some ways to use saved state with closures in php
  • scheming templates
  • scheming away
  • still scheming away

guild
Home » blogs » vlado's blog

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

vlado's blog | add new comment
Home » blogs » vlado's blog

dikini.net

spreading confusion by accident since 1970