news   ||   about   ||   download   ||   documentation   ||   development
created by chris
last edited by chris
"Dynasnips" are (usually fairly small) REBOL scripts using which you can adapt and extend Vanilla to your heart's content. Indeed, quite a bit of Vanilla itself is implemented using dynasnips.


If you don't know REBOL, don't panic. Albeit REBOL programming can be fairly different from what you might expect, it's actually a pretty easily learned (yet deep and powerful) language. For a very basic overview, read the Quick Introduction. Then proceed to the User's Guide - even if you don't have time to read it all, we recommend to at least skim it: to get a feel for what's in there. The Function Dictionary serves as a handy reference and the REBOL Cookbook contains dozens of (mostly) entry-level examples.


Dynasnips are stored in app-dir (as set in the Vanilla configuration file), which is usually <vanilla-root>apps/.

In there, create a new directory named tutorial, and within that, a plain text file named hello.r.

Dynasnips are REBOL objects following some structural conventions. The most important attribute certainly is handle, which is a function taking zero or one parameters. The simplest possible dynasnip looks as follows:

context [
handle: does [ "" ]
Which doesn't really do anything fancy except to create (and implicitly return) an empty string.

Let's spice that up a bit.

context [
handle: does [ "Hello World!" ]
Put that into the file (hello.r) you've created before, create a test snip, paste "{!tutorial.hello}", save and hope. If everything's alright, your first dynasnip will greet you with a friendly Hello World!. If you get an error, appending &debug=true to the URL will often reveal the cause of the failure.

hello, you!

Now let's turn our attention to the hot topic of '98, personalization. If you aren't happy being addressed as "World", we can peruse the one parameter of handle.
context [
handle: func [ param ] [
rejoin [ "Hello, " param "!" ]
If you reload your test snip, you should see Hello, none!, which points to one remaining problem with our potentially personalized first dynasnip: Given the case that no parameter is actually passed, param is set to none - a case which should be handled specially, usually with sensible default values.

context [
handle: func [ param ] [
either none? param [ "Hello World!" ] [ rejoin [ "Hello, " param "!" ] ]
Now change "{!tutorial.hello}" in your test snip to "{!tutorial.hello:Joe}", and you'll get a highly personalized Hello, Joe! (assuming that your name actually is Joe).
  welcome, stranger!
you might want to
log in or
  11 active users
unknown (11)
  recent edits
Copyright © 1999-2009 International Society for the Advancement of Planet-wide Vanillization