r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Dialects] Questions about how to create dialects

btiffin
21-Sep-2006
[129]
What would be the implications of  LOAD converting unmatchable types 
to string! behind the scene?  Or perhaps a new unstring! type to 
keep other dialecting more concise?
Maxim
21-Sep-2006
[130x5]
that's how I handle XML for example, a modified version of xml2rebxml.r 
.  I convert the tags into native rebol blocks, then handle the blocks 
within the application which expects the data... this way, you can 
more easily re-use code.
I have recently discovered the Issue! datatype.
and use it for many in-between values.
its like a power word, which accepts anything but a space.
(almost anything)
btiffin
21-Sep-2006
[135]
Ahh, just add a #.  Nice.
Maxim
21-Sep-2006
[136x3]
using string as a temporary data holder is ok too, as long as you 
can be sure the dataset will not get mixed up in a temporary value 
or actual string data.  either by its structure or content.
funny... I had been using rebol for 9 years and didn't know about 
that datatype... yet its extremely usefull
you just have to be carefull not to mix up other # using REBOL notation 
like char! (#"^/" ) or the serialized data format  (#[none] )
btiffin
21-Sep-2006
[139]
I can't say I've been 'using' Rebol for long, but I've been playing 
for quite a while now.  I discover something new every time I open 
up the system.  It's too cool how RT has put something as wide and 
deep as the ocean into a cup, a cup with blinking lights no less.
Maxim
21-Sep-2006
[140x2]
hehe  even if the cup has a few crack  ;-)
I feel its the most productive language out there.  not in how powerfull 
it CAN get but in how productive it IS from the onset of the very 
first time you use it.
btiffin
21-Sep-2006
[142]
Yep, that's what turned me all evangelical.
Gregg
22-Sep-2006
[143]
Issues can actually contain spaces, but they don't parse or mold 
that way. i.e. the datatype can hold them, but the lexical form doesn't 
allow it. Meaning you can get bitten, but do tricky things. :-)

>> a: #This issue has spaces in it
** Script Error: issue has no value
** Near: issue has spaces in it
>> a: to issue! "This issue has spaces in it"
== #This
>> probe a
#This
== #This
>> b: to string! a
== "This issue has spaces in it"
Maxim
22-Sep-2006
[144x2]
well, that holds for words to btw  ;-)
to = too
Ladislav
22-Sep-2006
[146]
just an alternative form:

>> form #[issue! "aaaaa aaa"]
== "aaaaa aaa"
Jerry
31-Oct-2006
[147x2]
Is the dialect conecpt original in REBOL? Or is it from another language? 
Does any other language have this concept too?
What makes a good dialect? Does anyone have any rules to share with 
us?
Graham
31-Oct-2006
[149]
DSLs have been around for a long time.
Gregg
31-Oct-2006
[150x2]
A "true" dialect in REBOL follows REBOL lexical form--i.e. you use 
block parsing--which is what would be called an embedded DSL in other 
languages. The concept is often associated with Lisp and its descendants. 
REBOL takes it furhter, and makes it easier (IMHO).
What makes a good dialect? That's a hard question to answer. What 
makes a good GPL (General Purpose Language)? There is no formula 
I know of, but I would say it should be:


* Focused. *Domain* specific is the key. If you don't know the domain, 
it will be hard to get it right.


* Well thought out and refined. Don't just take the first pass and 
call it good. Like a writer, think about the words you choose and 
how they're put together. 


* Small. Think about how the language will grow, but don't try to 
put too much in it.
Jerry
31-Oct-2006
[152]
Thank Gregg. It's very helpful. DSL stands for Domain-Specific Language, 
right? http://en.wikipedia.org/wiki/Domain-specific_language
Gabriele
31-Oct-2006
[153]
yes
Geomol
31-Oct-2006
[154x2]
As mentioned, you can parse in two different ways in REBOL: string 
parsing and block parsing. Recently (after using REBOL for years!!! 
Yes, you always keep discovering new things in REBOL.), I start to 
think about the two different ways of parsing, before I make a dialect. 
It's rather crucial, which way you choose, creating a dialect. String 
parsing is good for dialects, where you allow the user to type almost 
anything ... where you give lots of freedom. Block parsing is good, 
when you want the rules to be more narrow ... when you want the user 
to think in terms of works and symbols.


Latest I made the math dialect for NicomDoc. I choose string parsing 
giving lots of freedom. The dialect ended up specifying presentation 
more than semantic. The dielect is good to produce the formulas, 
just like you want them visualized. If (when?) I would make a math 
dialect, where I would put weight on the semantic (the meaning of 
the mathematical symbols), I would choose block parsing.
*terms of works and symbols* = terms of words and symbols
xavier
13-Jan-2007
[156]
.
Chris
10-Jun-2007
[157x4]
The next requirement for 'Filtered Import' <http://www.rebol.org/cgi-bin/cgiwrap/rebol/documentation.r?script=filtered-import.r>
is support of depth:
import [
    name ["Chris" "RG"]
    address [
        street "19th Terrace"
        town "Birmingham"
        zip 35205
    ]
][
    name: block! [string! length is more-than 2 string!]
    address: block! [
        street: string!
        apt: opt string!
        town: string!

        zip: issue! [5 digit opt "-" 4 digit] else "Must have a valid US 
        zip code"
    ]
]

== [
    name ["Chris" "RG"]
    address [
        street "19th Terrace"
        apt none
        town "Birmingham"
        zip #35205
    ]
]
I'm not quite sure how to pan this out.  Also, the 'name rule doesn't 
have any set words, it is operating on an unnamed series.  I think 
I want this type of rule to match the content.  In that if [string! 
string!] does not exactly describe the content, 'name throws a bad-format 
error.
But this target is achievable, there are some clear patterns.  And 
means that 'Filtered Import' can process more complex Rebol data 
(though not objects), basically Json class data.
Gregg
11-Jun-2007
[161]
Nice Chris. If you can nest named and unnamed value blocks, what 
you say seems logical, that the parent block is given as the error 
location.


Why do you use literal bitset values, and have the human-friendly 
format of charsets just as a comment in the code?
Chris
11-Jun-2007
[162]
You mean 'digit vs 'chars-n?  I've been using the latter for some 
time, mainly for consistency.  I'm going to migrate to more common 
names where there is a precedent.
Gregg
12-Jun-2007
[163]
I mean you have:
 comment {[
        chars-n:  charset [#"0" - #"9"]   ; numeric
        ....

But then the code actually uses:


    chars-n:  #[bitset! 64#{AAAAAAAA/wMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=}] 

Why have the second one, the #[bitset!] syntax, at all?
Chris
12-Jun-2007
[164x2]
I assumed the literal was faster to start...
Albeit, I'm not a master at measuring such things...
Gregg
12-Jun-2007
[166]
It will definitely be faster (about 8x here), but either one is so 
fast, that the difference is insignificant, unless you're doing it 
10,000 times, then you'll save .2 seconds or so.
Geomol
23-Jun-2007
[167x2]
Gregg wrote (in group Rebol vs Scheme):

I would *love* to see mini-primers on language design for Lisp, Forth, 
Logo, etc. in REBOL.

I've taken the first step for a BASIC dialect:

do http://www.fys.ku.dk/~niclasen/rebol/basic.r

It only knows a few commands so far: auto list new old
And these statements: end goto print rem run
And these functions: cos sin
Example of use:
BASIC

>auto
   10 print "Hello World!"
   20 0
>run
Hello World!
>list
   10 print "Hello World!"
>
Gregg
24-Jun-2007
[169]
Very cool John. Now, let me throw another thought into the mix, just 
for fun. 


If you were to write a language interpreter long ago, you would do 
it in a low level language like ASM or, later, C. In those languages 
you didn't have high level constructs like we have in REBOL. Certain 
languages have very specific models; consider Lisp and Forth, each 
has a few core definitions and the rest of the language it built 
on those. Lisp has lists, Forth has blocks, etc. 

With REBOL, we can do things in many ways. 


1) Leverage all REBOL has to offer. For example, how hard would it 
be to write a simple Lisp system if you (basically) use blocks for 
lists and supply a few standard Lisp functions? Is eval'ing a Lisp 
paren/list different than DOing a REBOL block?


2) Write lower level code, simulating how you would have to write 
a language using something like C or ASM. You could go as far as 
writing a simple virtual machine with its own set of ops.


3) Write dialects that are designed for building specific kinds of 
languages, showing the core concepts of languages, where they're 
similar, and where they differ; tools for teaching language design. 

I think all of those approaches have something to offer.
[unknown: 9]
24-Jun-2007
[170x2]
I think that making a Basic interpreter in Rebol is more useful, 
powerful, and educational than almost any other endeavour I have 
heard regarding Rebol (ever!).


-	People like the idea of Basic.  
-	Almost all programmers know some Basic
-	Although "basic" it tells programmers this is simple to do.
-	It is a great way to learn a dialect.

-	It has "news worthiness" would be good to write a compete dialect, 
and post on SlashDot.

-	If you can run QBasic - it would me instantly thousands if not 
millions of applications that could run instantly on any platform. 
Probably all would be faster even with graphics.
What may happen, is people (kids for example) would begin hacking 
old Basic applications rewritten in Rebol, to show off.

100 lines of Basic becoming 7 lines of Rebol for example.


There is a group of people hacking Nintendo emulators with a program 
that emulates the joystick, and attempt to play games in the shortest 
time possible.  It is very interesting, but why these types of things 
take off is that people can have fun, and without too much knowledge, 
show off their talents.
Geomol
24-Jun-2007
[172x2]
This Basic dialect parse in block mode, and this set some restrictions 
on the syntax, but it's probably faster and easier to program the 
parse rules. To make a QBasic would require, I used string parsing. 
Probably the same for most other languages. Unfortunately I don't 
have much time for this project atm., because I have 3 examins in 
the coming week, and after that I'm on vacation for 2 weeks. But 
I would like ot do more of this. Maybe we could make a real project 
with some goals!?
I added a few new things to the BASIC:

added DELETE command, added arguments to LIST, added STOP statement 
and some more (see source). Example of use:

>> do http://www.fys.ku.dk/~niclasen/rebol/basic.r
connecting to: www.fys.ku.dk
Script: "BASIC" (24-Jun-2007)
BASIC

>auto 5 5
    5 print "Line 5"
   10 rem goto 20
   15 blab
   20 print "Line 20"
   25 stop
   30 0
>run
Line 5

Mistake at line 15
>10 goto 20
>run
Line 5
Line 20

STOP at line 25
>
[unknown: 9]
24-Jun-2007
[174]
Yes, I was not suggesting YOU do this, but rather than it be a goal 
of the Rebol community...
Geomol
24-Jun-2007
[175x4]
I use this guide as a base for the BASIC interpreter: http://www.nvg.ntnu.no/bbc/doc/BBCUserGuide-1.00.pdf
I found it on this site: http://www.nvg.ntnu.no/bbc/docs.php3
I choosed that one, because I once owned a BBC Micro. I have no idea, 
how far that is from QBasic. But I guess Basic is Basic. They probably 
differ in stuff like graphics and sound.
To Gress's post:

1) Yes, it's interesting to find out, how much we get for free using 
e.g. blocks in REBOL to simulate lists in other languages. Maybe 
using hash! will benefit in some situations!?

2) Using rebcode is also a way to write lower level code. But it 
should also be possible to define REBOL functions, that work like 
(or simulate) the lower level commands in other languages. 

3) Yes, it would be interesting to find out, how languages differ 
in their cores.
LOL (I can't spell your name, sorry!)
*To Gregg's post*