tag:blogger.com,1999:blog-30192362566661797822024-03-26T23:38:13.564-07:00World Programming LanguageGeomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-3019236256666179782.post-33353696986465455272015-02-18T02:30:00.002-08:002015-02-18T02:30:48.489-08:00New alpha release 18-Feb-2015A new alpha release of The World Programming Language is out with a lot of new features. Check <a href="https://github.com/Geomol/World">World @ GitHub</a>Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.com2tag:blogger.com,1999:blog-3019236256666179782.post-70264557546936598782011-12-20T06:55:00.000-08:002011-12-22T15:32:19.050-08:00Structures and routines<i>Examples are from under OS X. If the code here wants to be copy/pasted to the World prompt, turn auto-brackets off with Ctrl-A in World.</i><br />
<br />
The <b>libc</b> routine <b>gettimeofday</b> returns the current calendar time as the elapsed time since the <b>epoch</b>. It takes pointers to two structures as arguments and fill those structures with data.<br />
<br />
First libc needs to be loaded:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> w> libc: load/library</span><span style="font-family: "Courier New",Courier,monospace;"> %/usr/lib/libc.dylib</span><br />
<br />
Then the structures and routine are defined:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> timeval: struct [</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> slong sec</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint32 usec</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ] none</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> timezone: struct [</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint minuteswest</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint dsttime</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ] none</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> gettimeofday: routine [</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> [typecheck]</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> libc "gettimeofday" [</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> tp [struct!] pointer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> tzp [struct!] pointer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ]</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ]</span><br />
<br />
<b>gettimeofday</b> can now be called:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> w> gettimeofday timeval timezone<br /> == 0</span><br />
<br />
<div style="font-family: inherit;">
<b>timeval</b> and <b>timezone</b> then holds the data. The routine <b>localtime_r</b> takes <b>time</b> and a <b>struct tm</b> as arguments and fill the structure with data:</div>
<span style="font-family: "Courier New",Courier,monospace;"> </span><br />
<span style="font-family: "Courier New",Courier,monospace;"> </span><span style="font-family: "Courier New",Courier,monospace;"> tm: struct [</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint sec</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint min</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint hour</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint mday</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint mon</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint year</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint wday</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint yday</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> sint isdst</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> slong gmtoff</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> pointer zone</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ] none</span><br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> localtime-r: routine [</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> [typecheck]</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> libc "localtime_r" [</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> time [struct!] pointer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> resultp [struct!] pointer</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ]</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> pointer handle!</span><br />
<span style="font-family: "Courier New",Courier,monospace;"> ]</span><br />
<br />
<span style="font-family: inherit;">The <b>time</b> argument is a pointer to a <i>slong</i> holding the seconds. But that's the first variable in the <b>timeval</b> structure, so we can just pass that:</span><br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
w> localtime-r timeval tm</div>
<div style="font-family: inherit;">
<br /></div>
<div style="font-family: inherit;">
Now <b>tm</b> is filled with data, and we can e.g. get the day of the year:</div>
<br />
<span style="font-family: "Courier New",Courier,monospace;"> w> tm/yday<br /> == 353</span><br />
<br />
There is some freedom in defining structures. C datatype and argument name can be exchanged. It's also possible to give initial values, so these two are the same:<br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
struct [float f] [1.0]</div>
<span style="font-family: "Courier New",Courier,monospace;"> struct [f float] [1.0]</span><br />
<div style="font-family: inherit;">
<br /></div>
<div style="font-family: inherit;">
<span style="font-family: inherit;">Now find some more interesting libraries to integrate with!</span></div>Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.com32tag:blogger.com,1999:blog-3019236256666179782.post-77594570412931653832011-12-18T03:13:00.000-08:002011-12-18T03:13:42.783-08:00Calling the outside WorldWorld can call routines in dynamic link libraries, and with the addition of handle! and struct! datatypes, all possible calls are supported. Let's see a simple example with the routines "strerror" and "puts" from LIBC:<br />(Examples are done under OS X.)<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> libc: load/library %/usr/lib/libc.dylib</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> strerror: make routine! [</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> libc "strerror" [</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> [] uint</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ]</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> pointer</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ]</span><br />
<br />
This is a simple definition of "strerror" without advanced typechecking and no description or specification of argument name or World datatype. "strerror" can now be used like this:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> w> strerror 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> == "Operation not permitted"</span><br />
<br />
The returned string can be saved in a variable:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> w> str: strerror 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> == "Operation not permitted"</span><br />
<br />
Then "puts" is defined:<br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
puts: make routine! [<br /> libc "puts" [<br /> [] pointer<br /> ]<br /> sint<br /> ]</div>
<br />
And "puts" can be used to write str to stdout:<br />
<br />
<div style="font-family: "Courier New",Courier,monospace;">
w> puts str<br /> Operation not permitted<br /> == 10</div>
<br />
"strerror" and "puts" can also be defined operating on handles, and in this case the string isn't copied to a World string! datatype. This time, the special attribute, typecheck, is needed, and I'll also put in some extra description and variable names:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> strerror: make routine! [</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> "Maps the error code to a descriptive error message."</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> [typecheck]</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> libc "strerror" [</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> errnum [integer!] uint "Error code"</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ]</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> pointer handle!</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ]</span><br style="font-family: "Courier New",Courier,monospace;" /><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> puts: make routine! [</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> "Writes a string to stdout followed by a newline."</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> [typecheck]</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> libc "puts" [</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> s [handle!] pointer "The string"</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ]</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> sint</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> ]</span><br />
<br />
Example of use:<br />
(notice "strerror" no longer returns a string)<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"> w> handle: strerror 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> w> puts handle</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> Operation not permitted</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> == 10</span><br />
<br />
Use the help function on a defined routine to see, how the routine is used:<br /><br /><span style="font-family: "Courier New",Courier,monospace;"> w> help strerror</span><br style="font-family: "Courier New",Courier,monospace;" />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.com4tag:blogger.com,1999:blog-3019236256666179782.post-4588606306237962392011-12-11T09:59:00.001-08:002011-12-11T10:02:12.130-08:00One week of open alphaIt has been a productive week:<br />
<br />
<br />
<ul>
<li>Routines got a more complete implementation</li>
<li>Added routines to HELP</li>
<li>Added new datatype, handle!</li>
<li>Series got an overhaul</li>
<li>Added library libs/version.w</li>
<li>Added new tests</li>
<li>Added new native function: AS</li>
<li>Added AS-BINARY, AS-STRING and WITH to rebol.w</li>
<li>Added /reset refinement to COMPILE function</li>
<li>Implemented error system</li>
<li>Added sys-utils with PRINT-LAST-ERROR function</li>
<li>Documentation was updated</li>
<li>Various fixes were carried out</li>
</ul>
<br />
The World project is on track.<br />
<br />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.com5tag:blogger.com,1999:blog-3019236256666179782.post-36257835852390295402011-12-04T01:09:00.001-08:002011-12-09T09:09:23.398-08:00IntroductionThis is the first public alpha release of the World Programming Language. World is strongly inspired by REBOL, developed by (some will say pioneer in these kinds of languages) Carl Sassenrath, which again is influenced by languages such as Self, Forth, Lisp and Logo.<br />
<br />
World is also influenced by Lua and Stackless Python.<br />
<br />
Why another language? After many years of programming experience, I find programming in most languages comparable to carving weird signs into stone. It's an enormous task, and when you look at all the weird signs and symbols, it quickly becomes unnecessarily complex and often unreadable.<br />
<br />
With World, it's like having a printing press a la Gutenberg. There is a minimum of syntax and strange symbols, and the code is very much human readable. Consequence is, that developers become more productive and produce better code with less errors.<br />
<br />
With my interest in science, a big goal with World is also to give scientists a tool to create their code with less effort, so they can concentrate on science instead of using their time to figure out strange programming languages.<br />
<br />
REBOL programmers will have a head start to learn and understand World, even if World is quite different with its virtual machine, different binding rules and other minor or major differences.<br />
<br />
The alpha release of World can be found at:<br />
<br />
<a href="https://github.com/Geomol/World" target="_new">https://github.com/Geomol/World</a><br />
<br />
!!! Remember this is an alpha release, so it's for testing only. Use it at your own risk. Do not distribute. !!!Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-82486054471019425752011-12-03T01:01:00.001-08:002011-12-11T10:07:05.891-08:00Countdown: 1In "Countdown: 9" earlier, we saw how World source code can be compiled into the machine language of the virtual machine (VM). Such compiled code can be disassembled, so the instructions for the VM can be seen:<br />
<br />
w> a: 1 <br />
== 1<br />
w> block: [a: a + 1]<br />
== [a: a + 1]<br />
w> do block ; this will compile and run the block of code<br />
== 2 ; and we see the result, 2<br />
w> disasm block<br />
<div style="background-color: #f3f3f3;">
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"> 0 GET_TVALUE 1 100312790</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> 1 LOADK 2 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> 2 ADD 1 1 2</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> 3 SET_TVALUE 100312790 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> 4 END 1</span></span></div>
<br />
Beside series, NEXT and BACK also works on integers, so I can write:<br />
<span style="background-color: #eeeeee;"><span style="background-color: #f3f3f3;"></span></span><br />
w> block: [next 'a]<br />
== [next 'a]<br />
w> disasm compile block ; this just compiles the block without running it<br />
<div style="background-color: #f3f3f3;">
<span style="font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"> 0 LOADK 1 100117a18</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> 1 NEXT 1 1</span><br style="font-family: "Courier New",Courier,monospace;" /><span style="font-family: "Courier New",Courier,monospace;"> 2 END 1</span></span></div>
<br />
This new block does the same as the block above, but in fewer instructions, because it uses call-by-word. If TRACE is ON, the VM code is shown, while it's being executed:<br />
<br />
w> trace on<br />
<div style="background-color: #f3f3f3;">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"> 0 END_EXECUTE 0</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"><span style="background-color: #f3f3f3;"> 0 END 0</span></span> </div>
w> now<br />
<div style="background-color: #f3f3f3;">
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"> 0 LOAD_NONE 0 2</span></span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"><span style="font-family: "Courier New",Courier,monospace;"> 0 NOW 0</span></span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"> 0 END_EXECUTE 0</span><br />
<span style="font-family: "Courier New",Courier,monospace; font-size: small;"> 0 END 0</span></div>
== 03-Dec-2011/10:13:55+1:00<br />
<br />
We came to the end of the countdown. In the last 10 days, the sources have grown with around 1,000 lines of C, so it's now close to 24,000 lines. And it'll continue growing to become version 1. The open alpha release of The World Programming Language can be on your computer tomorrow, so stay tuned!<br />
<br />
Finally, the smallest "Hello, World!" program in the known Universe:<br />
<br />
.<br />
<br />
Yes, it's a dot! Let's see it in action at the World prompt:<br />
<br />
w> .<br />
Hello, World!Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-68810208707481399612011-12-02T00:51:00.001-08:002011-12-02T01:01:30.928-08:00Countdown: 2World has much to do with dialects. Even World itself is a dialect (in fact several dialects), just like the language, we speak, consists of dialects.<br /><br />An example in World, where we want to expand the language with an object oriented dialect:<br /><br />w> do %mezz/object.w<br />w> obj: object [<br /> private [a: 1 b: 2] ; private data<br /> public [f: func [v][a + b + v] ; two public methods, f and set-a<br /> set-a: func [v][a: v]]<br />]<br />w> help obj ; notice we can't see A and B<br />obj is a context! of value:<br /> f function! [v]<br /> set-a function! [v]<br /><br />w> obj/f 1 ; calling f inside obj with argument 1<br />== 4<br />w> obj/set-a 40<br />== 40<br />w> obj/f 0<br />== 42<br /><br />World doesn't have keywords, as everything can be redefined. Beside the native functions and datatypes, the virtual machine understands directly, much of the basic part of the language is defined in World/Cortex. The Cortex part is just a World script named "cortex.w". The language is used to define itself and can be expanded into many dialects.<br /><br />Introducing call-by-word, which can be compared to call-by-reference in other languages:<br /><br />w> block: [a b c d]<br />== [a b c d]<br />w> next block ; this doesn't change BLOCK<br />== [b c d]<br />w> block<br />== [a b c d] ; as we can see here<br />w> next 'block ; this is call-by-word and changes BLOCK<br />== [b c d]<br />w> block<br />== [b c d] ; see!<br /><br />A lit-word! value is recognized by a pre-fixed apostrophe ('). The code generator changes lit-words into words, so the function, NEXT, gets a word in the call-by-word example above.<br />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-22329174657191830282011-12-01T00:53:00.001-08:002011-12-01T00:56:15.298-08:00Countdown: 3The KWATZ! datatype is used for values, which are not recognized as being of any known datatype.<br /><br />This can be utilized for example in dealing with UTM Coordinates.<br />LOAD can load anything:<br /><br />w> block: load "17T 630084 4833438"<br />== [#{313754} 630084 4833438]<br />w> type? block/1<br />== KWATZ!<br />w> to string! block/1<br />== "17T"<br />w> type? block/2<br />== integer!<br /><br />So it's easier to make dialects, that for example can deal with numbers with units, like:<br /><br />w> Earth: load "radius: 6,371.0km mass: 5.9736e24kg"<br />== [radius: #{362C3337312E306B6D} mass: #{352E393733366532346B67}]<br />w> type? earth/1<br />== set-word!<br />w> type? earth/2<br />== KWATZ!<br />w> parse Earth [some [set w set-word! set k kwatz! (print [w form k])]]<br />radius 6,371.0km<br />mass 5.9736e24kg<br />== true<br /><br />The KWATZ! datatype works much like the binary! datatype and can be converted to e.g. binary! or string! for further parsing.<br />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-4069913128384314792011-11-30T01:04:00.001-08:002011-12-09T11:53:52.729-08:00Countdown: 4Calling outside World can be achieved using dynamic linked libraries:<br />
<br />
CPU Time Inquiry under OS X:<br />
w> libc: load/library %/usr/lib/libc.dylib<br />
w> clock: make routine! [libc "clock" sint]<br />
<br />
Now CLOCK can be used like any other World function:<br />
w> do [<br />
t: clock<br />
add 2 2<br />
clock - t<br />
]<br />
== 11<br />
<br />
Get a SVID Random Number under Linux:<br />
w> libc: load/library %/lib/i386-linux-gnu/libc.so.6<br />
w> drand48: make routine! [libc "drand48" double]<br />
w> drand48<br />
== 3.907985046680551e-14<br />
<br />
Write a string to stdout under Windows:<br />
w> msvcrt: load/library %msvcrt.dll<br />
w> puts: make routine! [msvcrt "puts" [[string!] pointer] uint]<br />
w> puts "Hello, World!"<br />
Hello, World!<br />
<br />
The system can also be called:<br />
<br />
Under OS X:<br />
w> call "open http://world-lang.org"<br />
<br />
Under Linux:<br />
w> call "xdg-open http://world-lang.org"<br />
<br />
Under Windows:<br />
w> call "start http://world-lang.org"Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-63318410665380845292011-11-29T00:56:00.001-08:002011-11-29T00:58:42.068-08:00Countdown: 5Some of the math capabilities with complex numbers in World:<br /><br />w> z: 3+4i<br />== 3+4i<br />w> type? z<br />== complex!<br />w> z/Re ; or z/re or z/1<br />== 3.0<br />w> z/Im ; or z/im or z/2<br />== 4.0<br />w> abs z<br />== 5.0<br />w> arg z<br />== 0.927295218001612<br />w> z * z <br />== -7+24i<br />w> sqrt z<br />== 2+i<br />w> cos z<br />== -27.03494560307422-3.851153334811777i<br />w> ln z<br />== 1.6094379124341+0.927295218001612i<br />w> e ** z<br />== -13.12878308146216-15.20078446306795i<br />w> i: 1i<br />== 1i<br />w> e ** (i * pi) + 1 ; Euler's identity<br />== 1.224646799147353e-16i ; Rounding please!<br />w> first e ** (i * pi) + 1<br />== 0.0<br />w> round/to abs e ** (i * pi) + 1 1e-15<br />== 0.0<br /><br />It's ok to put in some parentheses for readability:<br /><br />w> round/to (abs (e ** (i * pi) + 1)) 1e-15<br />== 0.0<br /><br />Some may prefer a caret (^) as the power operator, and that can be defined:<br /><br />w> ^: :**<br />w> 0+1i ^ 0<br />== 1+0i<br /><br />What does the next two lines do?<br /><br />f: func[c][z: 0i n: 0 while[999 > next 'n][if 4 < abs z: z * z + c[return n]]]<br />for y -59 18 1[for x -39 38 1[prin either f x * 1i + y / 40[" "]['*]]prin lf]<br />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-5701054535084117042011-11-28T01:00:00.001-08:002011-11-28T01:01:09.024-08:00Countdown: 6Networking.<br />(Examples from the World prompt.)<br /><br />A server process:<br /><br />w> listen: open tcp://:8080<br />w> port: first listen ; This makes the process wait for a client - see below<br />w> to string! copy/part port 3<br />== "ok?"<br />w> insert port "fine!"<br />w> close port<br />w> close listen<br /><br />A client process:<br /><br />w> port: open tcp://127.0.0.1:8080<br />w> insert port "ok?"<br />w> to string! copy/part port 5<br />== "fine!"<br />w> close port<br />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-65433181377515399782011-11-27T01:00:00.001-08:002011-11-27T01:01:13.778-08:00Countdown: 7The range! datatype.<br /><br />w> type? 2-5<br />== range!<br />w> block: [a b c d e f g]<br />== [a b c d e f g]<br />w> block/2-5<br />== [b c d e]<br />w> block/4-4<br />== [d]<br />w> block/4-3<br />== [c]<br />w> block/4-1<br />== [a b c]<br /><br />Another useful shortcut:<br /><br />w> a: [2.4 3.1 4.2 2.8 6.3 3.0 4.8]<br />== [2.4 3.1 4.2 2.8 6.3 3.0 4.8]<br />w> a > 4.1<br />== [4.2 6.3 4.8]<br />
<br />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-72205963662126051792011-11-26T01:02:00.001-08:002011-11-26T01:05:23.724-08:00Countdown: 8Like functions, it's also possible to make user-defined operators. Here's a simple example.<br />
<br />
The World Programming Language has different datatypes known as series to hold collections of data. One is the block! datatype:<br /><br /> block: [1 2 "blue" 3]<br /><br />The value, "blue", can be removed from the block with this code:<br /><br /> remove find block "blue"<br /><br />The same can be achieved using the FROM operator:<br /><br /> remove "blue" from block<br /><br />Some may prefer to write it this way to make the code more readable. FROM is defined as:<br /><br /> from: operator [<br /> "Finds a value in a series." <br /> value <br /> series [series!]<br /> ][<br /> find series value<br /> ]<br /><br />To insert "blue" back into the block after 2, instead of writing:<br /><br /> insert next find block 2 "blue"<br /><br />you could write:<br /><br /> insert block after 2 "blue"<br /><br />where AFTER is defined as:<br /><br /> after: operator [series value] [next find series value]<br /><br />The same could in this example be achieved with:<br /><br /> insert find block 3 "blue"<br />or<br /> insert block before 3 "blue"<br />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-43437371175902023932011-11-25T01:08:00.001-08:002011-11-25T01:09:25.564-08:00Countdown: 9World source is compiled to the virtual machine on the fly, when the code is run. Once a piece of code is compiled, it can be run again and again on the virtual machine without further compilation.<br /><br />Code can also be recompiled in a different context. An example from the World prompt:<br /><br />w> a: b: 0<br />== 0<br />w> f: func [v] [a + b + v]<br />w> compiled? :f<br />== false<br />w> f 1<br />== 1<br />w> compiled? :f<br />== true<br />w> c1: context [a: 1 b: 2]<br />w> c2: context [a: 1 b: 40]<br />w> compile/at :f c1<br />w> f 1<br />== 4<br />w> compile/at :f c2<br />w> f 1<br />== 42<br />w> compile :f<br />w> f 1<br />== 1<br />Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.comtag:blogger.com,1999:blog-3019236256666179782.post-22472451977456094142011-07-04T14:12:00.000-07:002011-11-25T07:38:53.061-08:00Countdown: 10The World Programming Language has much in common with a human language in written form. This means the language is a sequence of values recognized as being of different datatypes - like words, numbers, dates, URLs, parentheses, and many other - with a minimum of syntax.<br />
<div style="text-align: center;">
<div style="text-align: left;">
<br />
The version presented here is an implementation of World in a custom made virtual machine (VM). At present, the virtual machine operates with more than 80 opcodes and more than 40 datatypes.</div>
<div style="text-align: left;">
<br />
World is written in ANSI C with portability in mind. The source code is at present close to 23,000 lines of C, binary is less than half a MB and a little more than 100k compressed.</div>
<div style="text-align: left;">
</div>
</div>Geomolhttp://www.blogger.com/profile/17332398271758070462noreply@blogger.com