• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

AltME groups: search

Help · search scripts · search articles · search mailing list

results summary

worldhits
r4wp3
r3wp5
total:8

results window for this page: [start: 4 end: 8]

world-name: r3wp

Group: Core ... Discuss core issues [web-public]
JaimeVargas:
7-Apr-2005
I hope this is useful for someone

REBOL []

rest: func [s [series!]][skip s 1]

define-object: func [
	spec [block!] 
	/local 

  arg-spec ctx-spec object-name constructor-name predicate-name attributes
		spec-rule type-spec continue? w
][
	arg-names: copy []

	continue?: [none] ;used to stop parsing
	name-rule: [set w word! (insert tail arg-names w)]

 type-rule: [set w word! (unless datatype? attempt [get w] [continue?: 
 [end skip]])]

 spec-rule: [name-rule some [name-rule opt [into [some [type-rule 
 continue?]]]]]

	if any [
		not parse spec spec-rule
		arg-names <> unique arg-names
	][
		make error! "invalid spec"
	]

    object-name: to-string first arg-names
	constructor-name: to-word join 'make- object-name
	predicate-name: to-word join first arg-names '?
	attributes: rest arg-names

	arg-spec: copy []
	foreach itm attributes [
		insert tail arg-spec reduce [
			to-word join itm '-value
			either block? w: select spec itm [w][[any-type!]]
		]
	]

	ctx-spec: copy []
	arg-names: extract arg-spec 2 1
	repeat i length? attributes [

  insert tail ctx-spec reduce [to-set-word attributes/:i to-get-word 
  arg-names/:i]
	]

	;create constructor function
	set constructor-name make function! 

  compose [(reform ["Makes a new" uppercase object-name "object with 
  attributes" mold attributes]) (arg-spec)]
		compose/only [make object! (ctx-spec)] ;body

	;create predicate function
	set predicate-name make function! 

  compose [(reform ["Determines if value is a" uppercase object-name 
  "object"]) value [object!] /local types]
		compose/deep/only [
			either (attributes) = rest first value [
				foreach itm (attributes) [
					unless any [

      [any-type!] = types: select (arg-spec) to-word join itm '-value
						find types type?/word value/:itm
					][return false]
				]
				true
			][
				false
			]
		] 
]
Janko:
21-Jan-2010
I will give another example where I claim doing a dialect for it 
all is useless option. So you have a rebol server that holds a big 
block of users in ram you send it 2 functions a filter >> function 
[ U ] [ all [ greater? U/age 20 lesser U/age 30 equal? U/gender 'female 
] << and a mapping function >> function [ U ] [ uppercase rejoin 
[ U/name " " U/surname ] ] << server will accept the code and collect 
items where first returns true then process them vith mapping function 
join them with reducing >> function [ U ACC ] [ rejoin [ ACC ", " 
U ]<<  function and return the result.
Group: I'm new ... Ask any question, and a helpful person will try to answer. [web-public]
Janko:
8-Jan-2009
I have another question about parse, if I may.. I am trying to make 
a parse block that will uppercase all letters after the . ! or ? 
. I did it just for dots, but I can't make it for all 3  ( one alternative 
is to call parse 3 times each time with different separator char. 
The problem can be observed here, and happens because [ A | B | C 
] pattern first looks for A and if it doesn't find a checks B , which 
means it will skip B if A is after B. Is there any way to say "use 
any of those chars - *whichever comes first" ? .. example where you 
can see the  problem:
Group: Parse ... Discussion of PARSE dialect [web-public]
JaimeVargas:
27-Jun-2006
I think I missunderstood the problem. I thought the the emphasis 
was not for words all in uppercase. Just ther first char.
Group: SQLite ... C library embeddable DB [web-public].
Ashley:
13-Feb-2006
sqlite3-protocol.r has a minor bug whereby locals/cols are not cleared. 
Fix is to add a "clear cols" at the beginning of the ' sqlite-exec 
func. Two other changes I made to this function were:


1) Changing “SQLITE_TEXT [any [attempt [load val: sqlite3/column_text 
stmt j] val]]” so as REBOL values are returned, and

2) Removing the /only clause from "system/words/insert/only tail 
result col" for those that prefer flat data structures (i.e. non-blocked 
records)

Finally, a simple wrapper makes the whole thing more usable:

context [

	db: none

	set 'open-db func [name [file!]] [
		db: open join sqlite://localhost/ name
	]

	set 'close-db does [
		close db
	]

	set 'describe func ['table [word!]] [

  insert db rejoin ["select type, name, sql from sqlite_master where 
  upper(tbl_name) = '" uppercase form table "' order by rootpage"]
		db/locals/sqlresult
	]

	set 'sql function [arg [string! block!]] [statement] [
		case [
			string? arg [insert db arg]
			string? first arg [
				statement: copy first arg
				repeat i -1 + length? arg [
					replace/all statement join ":" i pick arg i + 1
				]
				insert db statement
			]
		]
		db/locals/sqlresult
	]
]

which lets you do stuff like:

>> open-db %test.db
>> sql "create table t1 (col1 INTEGER, col2 TEXT)"
== []
>> describe t1
== [table t1 "CREATE TABLE t1 (col1 INTEGER, col2 TEXT)"]
>> sql reduce ["insert into t1 values (1,':1')" now/date]
== []
>> sql "select * from t1"
== [1 13-Feb-2006]
>> close-db
1 / 8[1]