Our examples directory needs some love as it lags behind the new features/syntax available in more or less recent Boo versions.
As this task is both self-learning and has a low-barrier of entry, it would be nice to see the community involved in this effort.
Ideally new examples would all follow a common template header like this updated `ifdef.boo` example (much shorter thanks to new features/syntax since it was originally written):
{code} """ Description: This example shows how to write a macro that behaves differently depending compilation parameters (here the presence of a 'BOO' define symbol)
Code below will display "Yeah! BOO is defined!" only if compiled with a BOO define symbol (e.g through `booc -d:BOO ifdef.boo`)
A short `Description:` about the example would be required, `Exercise:` would be nice to have the more often the better.
I suggest we remove the big/noisy copyright header that does not really make sense for (such simple) examples imo. Adding an `Author: FirstName Name <email>` on the first line is acceptable though.
Let's use this thread to post (both inline _and_ attached) updated (or new) examples featuring what Boo can do - nowadays.
We'll see how the thread went next Saturday (14th Feb. - Valentine day - hence why you'd better show your love to Boo! ;-) ) .. and then later merge back the - hopefully numerous - updated/new examples back in the repository.
> Our examples directory needs some love as it lags behind the new
> features/syntax
> available in more or less recent Boo versions.
> As this task is both self-learning and has a low-barrier of entry, it would
> be
> nice to see the community involved in this effort.
> Ideally new examples would all follow a common template header like this
> updated
> `ifdef.boo` example (much shorter thanks to new features/syntax since it was
> originally written):
> {code}
> """
> Description:
> This example shows how to write a macro that behaves differently
> depending compilation parameters (here the presence of a 'BOO' define
> symbol)
> Code below will display "Yeah! BOO is defined!" only if compiled with
> a BOO define symbol (e.g through `booc -d:BOO ifdef.boo`)
> A short `Description:` about the example would be required, `Exercise:`
> would be
> nice to have the more often the better.
> I suggest we remove the big/noisy copyright header that does not really make
> sense for (such simple) examples imo.
> Adding an `Author: FirstName Name <email>` on the first line is acceptable
> though.
> Let's use this thread to post (both inline _and_ attached) updated (or new)
> examples
> featuring what Boo can do - nowadays.
> We'll see how the thread went next Saturday (14th Feb. - Valentine day -
> hence why
> you'd better show your love to Boo! ;-) ) .. and then later merge back the -
> hopefully numerous -
> updated/new examples back in the repository.
On Sat, Feb 7, 2009 at 5:18 PM, Cedric Vivier <cedr...@neonux.com> wrote: > We'll see how the thread went next Saturday (14th Feb. - Valentine day - > hence why > you'd better show your love to Boo! ;-) ) .. and then later merge back the > - hopefully numerous - > updated/new examples back in the repository.
Well, I'll start to get the ball rolling then ;(
A new example using the new OmittedExpression (or dot-prefix) that is available in trunk :
Définitely, macros are not for me :-(
I don't know if I don't make any effort or if it is a boo-developers-
only features or what else, but all the syntax remains
incomprehensible for me.
The most usefull idea for macros is parsing LINQ expression like 'from
i in list where i.fld > 5 select i.name'.
Is it possible with current state of macro support?
> Définitely, macros are not for me :-(
> I don't know if I don't make any effort or if it is a boo-developers-
> only features or what else, but all the syntax remains
> incomprehensible for me.
On Mon, Feb 9, 2009 at 6:05 AM, Thorna <fo...@wanadoo.fr> wrote: > Définitely, macros are not for me :-( > I don't know if I don't make any effort or if it is a boo-developers- > only features or what else, but all the syntax remains > incomprehensible for me.
Even the first `ifdef` example? What don't you get in it?
You know how Boo transforms source code into assemblies, wrt to macros it can be summed up grossly as: !) read source code (obviously) 2) parses source into an AST representation (a tree of nodes [inheriting Node], e.g MethodInvocationExpression) 3) expand macro statements (runs the `macro ifdef:` body during compilation and replace `ifdef` occurences by the nodes yielded [`yield` alone is a shortha nd for yield ifdef.Body]) 4) expanded AST representation (the one you can see with -p:boo booc parameter for instance) 5) emit expanded AST into CIL bytecode.
It can be very useful, not only for implementing linq-style syntax but any kind of DSL (e.g Specter), and more generally to shortcut long/repetitive code (instead of you writing the code - like `print e` is actually a macro that expands to `System.Console.WriteLine(e)` ). I'm sure you can find handy usages for this ;-)
Anyways examples week is not about 'bleeding-edge' macros only, feel free to contribute updated/new examples about something else, there is plenty of them needing update/cleanup in examples/ ;-)
On Mon, Feb 9, 2009 at 12:19 AM, Cedric Vivier <cedr...@neonux.com> wrote:
> On Mon, Feb 9, 2009 at 6:05 AM, Thorna <fo...@wanadoo.fr> wrote:
>> Définitely, macros are not for me :-(
>> I don't know if I don't make any effort or if it is a boo-developers-
>> only features or what else, but all the syntax remains
>> incomprehensible for me.
> Even the first `ifdef` example? What don't you get in it?
> You know how Boo transforms source code into assemblies, wrt to macros it
> can be summed up grossly as:
> !) read source code (obviously)
> 2) parses source into an AST representation (a tree of nodes [inheriting
> Node], e.g MethodInvocationExpression)
> 3) expand macro statements (runs the `macro ifdef:` body during compilation
> and replace `ifdef` occurences by the nodes yielded [`yield` alone is a
> shortha nd for yield ifdef.Body])
> 4) expanded AST representation (the one you can see with -p:boo booc
> parameter for instance)
> 5) emit expanded AST into CIL bytecode.
> It can be very useful, not only for implementing linq-style syntax but any
> kind of DSL (e.g Specter), and more generally to shortcut long/repetitive
> code (instead of you writing the code - like `print e` is actually a macro
> that expands to `System.Console.WriteLine(e)` ).
> I'm sure you can find handy usages for this ;-)
> Anyways examples week is not about 'bleeding-edge' macros only, feel free
> to contribute updated/new examples about something else, there is plenty of
> them needing update/cleanup in examples/ ;-)
> Are there any well known, open source, macro projects other than specter?
> On Mon, Feb 9, 2009 at 12:19 AM, Cedric Vivier <cedr...@neonux.com> wrote:
>> On Mon, Feb 9, 2009 at 6:05 AM, Thorna <fo...@wanadoo.fr> wrote:
>>> Définitely, macros are not for me :-(
>>> I don't know if I don't make any effort or if it is a boo-developers-
>>> only features or what else, but all the syntax remains
>>> incomprehensible for me.
>> Even the first `ifdef` example? What don't you get in it?
>> You know how Boo transforms source code into assemblies, wrt to macros it
>> can be summed up grossly as:
>> !) read source code (obviously)
>> 2) parses source into an AST representation (a tree of nodes [inheriting
>> Node], e.g MethodInvocationExpression)
>> 3) expand macro statements (runs the `macro ifdef:` body during
>> compilation and replace `ifdef` occurences by the nodes yielded [`yield`
>> alone is a shortha nd for yield ifdef.Body])
>> 4) expanded AST representation (the one you can see with -p:boo booc
>> parameter for instance)
>> 5) emit expanded AST into CIL bytecode.
>> It can be very useful, not only for implementing linq-style syntax but any
>> kind of DSL (e.g Specter), and more generally to shortcut long/repetitive
>> code (instead of you writing the code - like `print e` is actually a macro
>> that expands to `System.Console.WriteLine(e)` ).
>> I'm sure you can find handy usages for this ;-)
>> Anyways examples week is not about 'bleeding-edge' macros only, feel free
>> to contribute updated/new examples about something else, there is plenty of
>> them needing update/cleanup in examples/ ;-)
>>Expression above could be expressed like this *right now*:
I would say that it would be interesting to all, how to use macros
facility to resolve this(such) problem.
For example to expand Boo by another interesting functional
expressions,
that can nested in each other. I know about support nested macros, but
don't know simple way ;) how use the facilities at whole for similar
tasks.
On 9 фев, 16:14, Ayende Rahien <aye...@ayende.com> wrote:
> On Mon, Feb 9, 2009 at 4:00 PM, Justin Chase <justin.m.ch...@gmail.com>wrote:
> > Are there any well known, open source, macro projects other than specter?
> > On Mon, Feb 9, 2009 at 12:19 AM, Cedric Vivier <cedr...@neonux.com> wrote:
> >> On Mon, Feb 9, 2009 at 6:05 AM, Thorna <fo...@wanadoo.fr> wrote:
> >>> Définitely, macros are not for me :-(
> >>> I don't know if I don't make any effort or if it is a boo-developers-
> >>> only features or what else, but all the syntax remains
> >>> incomprehensible for me.
> >> Even the first `ifdef` example? What don't you get in it?
> >> You know how Boo transforms source code into assemblies, wrt to macros it
> >> can be summed up grossly as:
> >> !) read source code (obviously)
> >> 2) parses source into an AST representation (a tree of nodes [inheriting
> >> Node], e.g MethodInvocationExpression)
> >> 3) expand macro statements (runs the `macro ifdef:` body during
> >> compilation and replace `ifdef` occurences by the nodes yielded [`yield`
> >> alone is a shortha nd for yield ifdef.Body])
> >> 4) expanded AST representation (the one you can see with -p:boo booc
> >> parameter for instance)
> >> 5) emit expanded AST into CIL bytecode.
> >> It can be very useful, not only for implementing linq-style syntax but any
> >> kind of DSL (e.g Specter), and more generally to shortcut long/repetitive
> >> code (instead of you writing the code - like `print e` is actually a macro
> >> that expands to `System.Console.WriteLine(e)` ).
> >> I'm sure you can find handy usages for this ;-)
> >> Anyways examples week is not about 'bleeding-edge' macros only, feel free
> >> to contribute updated/new examples about something else, there is plenty of
> >> them needing update/cleanup in examples/ ;-)
On Tue, Feb 10, 2009 at 12:29 AM, Spruce Weber <timber...@gmail.com> wrote: > I don't know if AstAttributes fall into the same category, but I used > one to implement a sort of mixin pattern to avoid some boilerplate > code...
Woohoo, first new example, kudos to you Spruce! :-) You are right on spot, there is no 'category', any example of code using boo features is good :) (alternatively anyone can take on improving/updating an existing one: http://svn.boo.codehaus.org/browse/boo/boo/trunk/examples )
If you can just add a small Description: header (and Author: if you'd like to) explaining what it does and showing the minimum code about how to use it, that would be *perfect* !!
Where is the documentation for the "macro" macro? Where is the
documentation for using the AST and those cool [| AST expressions |]
with $interpolation?
I understand the ifdef macro, but it doesn't help us learn to write
more sophisticated macros.
I would like to write a macro in which you could write something
like...
x = 12
y = 7.0
z = "11"
total = 0.0
witheach Var in x, y, z:
total += Convert.ToDouble(Var)
and the macro would expand this to
x = 12
y = 7.0
z = "11"
total = 0.0
total += Convert.ToDouble(x)
total += Convert.ToDouble(y)
total += Convert.ToDouble(z)
But I don't know how to get started. Also, Rodrigo just said that this
ifdef macro only works in trunk, but NAnt didn't build trunk
successfully for me. Nant's final output was...
Boo.NAnt.Tasks:
[exec] Not a valid directory for -lib argument: 'C:\Program Files
\nant-0.85\bin" -r:NAnt.Core.dll -r:NAnt.DotNetTasks.dll src/
Boo.NAnt.Tasks/UpdateAssemblyVersionTask.boo src/Boo.NAnt.Tasks/
InsertLicenseTask.boo src/Boo.NAnt.Tasks/BoocTask.boo src/
Boo.NAnt.Tasks/BooTask.boo src/Boo.NAnt.Tasks/AbstractBooTask.boo'
[exec] Boo Compiler version 0.9.0.3203 (CLR 2.0.50727.3053)
[exec] Fatal error: System.ApplicationException: No inputs
specified
[exec] at BooC.App.Run(String[] args) in c:\Download\boo 0.9
svn\src\booc\App.cs:line 108.
On Mon, Feb 9, 2009 at 9:07 AM, Qwertie <qwertie...@gmail.com> wrote:
> Where is the documentation for the "macro" macro? Where is the
> documentation for using the AST and those cool [| AST expressions |]
> with $interpolation?
> I understand the ifdef macro, but it doesn't help us learn to write
> more sophisticated macros.
> I would like to write a macro in which you could write something
> like...
> x = 12
> y = 7.0
> z = "11"
> total = 0.0
> witheach Var in x, y, z:
> total += Convert.ToDouble(Var)
> and the macro would expand this to
> x = 12
> y = 7.0
> z = "11"
> total = 0.0
> total += Convert.ToDouble(x)
> total += Convert.ToDouble(y)
> total += Convert.ToDouble(z)
> But I don't know how to get started. Also, Rodrigo just said that this
> ifdef macro only works in trunk, but NAnt didn't build trunk
> successfully for me. Nant's final output was...
> Boo.NAnt.Tasks:
> [exec] Not a valid directory for -lib argument: 'C:\Program Files
> \nant-0.85\bin" -r:NAnt.Core.dll -r:NAnt.DotNetTasks.dll src/
> Boo.NAnt.Tasks/UpdateAssemblyVersionTask.boo src/Boo.NAnt.Tasks/
> InsertLicenseTask.boo src/Boo.NAnt.Tasks/BoocTask.boo src/
> Boo.NAnt.Tasks/BooTask.boo src/Boo.NAnt.Tasks/AbstractBooTask.boo'
> [exec] Boo Compiler version 0.9.0.3203 (CLR 2.0.50727.3053)
> [exec] Fatal error: System.ApplicationException: No inputs
> specified
> [exec] at BooC.App.Run(String[] args) in c:\Download\boo 0.9
> svn\src\booc\App.cs:line 108.
On Tue, Feb 10, 2009 at 1:07 AM, Qwertie <qwertie...@gmail.com> wrote: > x = 12 > y = 7.0 > z = "11" > total = 0.0 > witheach Var in x, y, z: > total += Convert.ToDouble(Var)
> and the macro would expand this to
> x = 12 > y = 7.0 > z = "11" > total = 0.0 > total += Convert.ToDouble(x) > total += Convert.ToDouble(y) > total += Convert.ToDouble(z)
> ifdef macro only works in trunk, but NAnt didn't build trunk > successfully for me. Nant's final output was...
> Boo.NAnt.Tasks: > [exec] Not a valid directory for -lib argument: 'C:\Program Files > \nant-0.85\bin" -r:NAnt.Core.dll -r:NAnt.DotNetTasks.dll src/
Sorry our build file on Windows does not work when NAnt is installed in a directory with a whitespace (such as the dreaded "Program Files";), try reinstalling NAnt in another non-whitespacey directory.
One concept that I think needs to be emphasized (may not be clear to everyone) is that macros and AstAttributes are objects that are instantiated and used at compiletime, not runtime; that they are for manipulating the AST/code before producing an assembly.
> Where is the documentation for the "macro" macro? Where is the
> documentation for using the AST and those cool [| AST expressions |]
> with $interpolation?
Also, I forgot to add, where is the documentation for the AST classes?
Another question: can macros have memory? I think it would be cool to
have a pair of macros, let's call them "define" and "expand". define
would be used something like this:
define PointClass(P, T):
class P:
public constructor(x as T, y as T):
X=x; Y=y
public X as T
public Y as T
static def op_Addition(a as P, b as P):
return P(a.X+b.X, a.Y+b.Y)
static def op_Subtraction(a as P, b as P):
return P(a.X-b.X, a.Y-b.Y)
static def op_Multiply(a as P, b as P):
return a.X*b.X + a.Y*b.Y
and expand would be used like this to define three different kinds of
points:
> > Boo.NAnt.Tasks:
> > [exec] Not a valid directory for -lib argument: 'C:\Program Files
> > \nant-0.85\bin" -r:NAnt.Core.dll -r:NAnt.DotNetTasks.dll src/
> Sorry our build file on Windows does not work when NAnt is installed in a
> directory with a whitespace (such as the dreaded "Program Files";), try
> reinstalling NAnt in another non-whitespacey directory.
Hmm, looks like the source files can't be in a path that contains
spaces either. You know, I always thought 21st century technology
would support the space character. There's a reason Microsoft put a
space in "Program Files" back in 1995.
update-vs2005-env:
[exec] System.IO.DirectoryNotFoundException: Could not find a
part of the path 'C:\Download\boo
%200.9%20svn\src\Boo.Lang'.
[exec] at System.IO.__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
[exec] at System.IO.Directory.InternalGetFileDirectoryNames
(String path, String userPathOrig
inal, String searchPattern, Boolean includeFiles, Boolean includeDirs,
SearchOption searchOption)
[exec] at System.IO.Directory.GetFiles(String path, String
searchPattern, SearchOption searc
hOption)
[exec] at System.IO.Directory.GetFiles(String path)
[exec] at Boo.Lang.Useful.IO.WalkModule.listFiles
$130.$.MoveNext()
[exec] at Update-vs2005-envModule.updateProjectFile(String
fname) in C:\Download\boo 0.9 svn
\scripts\update-vs2005-env.boo:line 89
[exec] at Update-vs2005-envModule.Main(String[] argv) in C:
\Download\boo 0.9 svn\scripts\upd
ate-vs2005-env.boo:line 139
On Tue, Feb 10, 2009 at 1:52 AM, psi <simon.pl...@googlemail.com> wrote: > im not sure this is as straightforward as it sounds, some basic > organization may be needed;how about breaking it down a bit, by starting > with a list of features, > so less duplication.
You can have a look at current examples/, I think the current organization of the directory is more or less okay. It just needs some cleaning/updating and examples of (newer) features.
then again, is it possible to have both an example and a test in one
> piece of code, and really get some value out of this?
Not sure what you mean by "and a test", what I meant is that most examples (if possible) should build as an .exe, so that one can see the result, hence being able to start playing/modifying it directly. I think the value is here, playing with small bits of code is a great way to learn. Compared to a testcase that is `contrived` code without meaning except testing _one_ feature, an example should be demonstrating something that could be used in real-world (and thus does not have to be limited to one and only feature).
Ayende: Your book will have some boo specific examples won't it?
I've attached a bunch of examples that I used for a code camp presentation I
did last october. This includes a solution with many different simple
projects that open in (the last version of) #Develop and show off various
features of boo. It also comes with a very simple slide deck I used to get
things going.
The samples include:
- IQuackFu and Duck Typing
- Auto casting
- Closures
- Pipelines
- Regular expressions
- Type inference
- DSL Macros
- Specter
- Functional tricks
And a lot of other fun stuff... Is this the best way to submit this code or
would you rather I formally submit it as a patch or something?
On Mon, Feb 9, 2009 at 8:14 AM, Ayende Rahien <aye...@ayende.com> wrote:
> Binsor
> Simple State Machine
> On Mon, Feb 9, 2009 at 4:00 PM, Justin Chase <justin.m.ch...@gmail.com>wrote:
>> Are there any well known, open source, macro projects other than specter?
>> On Mon, Feb 9, 2009 at 12:19 AM, Cedric Vivier <cedr...@neonux.com>wrote:
>>> On Mon, Feb 9, 2009 at 6:05 AM, Thorna <fo...@wanadoo.fr> wrote:
>>>> Définitely, macros are not for me :-(
>>>> I don't know if I don't make any effort or if it is a boo-developers-
>>>> only features or what else, but all the syntax remains
>>>> incomprehensible for me.
>>> Even the first `ifdef` example? What don't you get in it?
>>> You know how Boo transforms source code into assemblies, wrt to macros it
>>> can be summed up grossly as:
>>> !) read source code (obviously)
>>> 2) parses source into an AST representation (a tree of nodes [inheriting
>>> Node], e.g MethodInvocationExpression)
>>> 3) expand macro statements (runs the `macro ifdef:` body during
>>> compilation and replace `ifdef` occurences by the nodes yielded [`yield`
>>> alone is a shortha nd for yield ifdef.Body])
>>> 4) expanded AST representation (the one you can see with -p:boo booc
>>> parameter for instance)
>>> 5) emit expanded AST into CIL bytecode.
>>> It can be very useful, not only for implementing linq-style syntax but
>>> any kind of DSL (e.g Specter), and more generally to shortcut
>>> long/repetitive code (instead of you writing the code - like `print e` is
>>> actually a macro that expands to `System.Console.WriteLine(e)` ).
>>> I'm sure you can find handy usages for this ;-)
>>> Anyways examples week is not about 'bleeding-edge' macros only, feel free
>>> to contribute updated/new examples about something else, there is plenty of
>>> them needing update/cleanup in examples/ ;-)
Um, the book _is_ called building DSL with Boo
My publisher informed me that while I would really like to write the
examples in Sanskrit, the title sort of oblige me to include at least a few
Boo samples.
On Mon, Feb 9, 2009 at 9:44 PM, Justin Chase <justin.m.ch...@gmail.com>wrote:
> Ayende: Your book will have some boo specific examples won't it?
> I've attached a bunch of examples that I used for a code camp presentation
> I did last october. This includes a solution with many different simple
> projects that open in (the last version of) #Develop and show off various
> features of boo. It also comes with a very simple slide deck I used to get
> things going.
> And a lot of other fun stuff... Is this the best way to submit this code or
> would you rather I formally submit it as a patch or something?
> On Mon, Feb 9, 2009 at 8:14 AM, Ayende Rahien <aye...@ayende.com> wrote:
>> Binsor
>> Simple State Machine
>> On Mon, Feb 9, 2009 at 4:00 PM, Justin Chase <justin.m.ch...@gmail.com>wrote:
>>> Are there any well known, open source, macro projects other than specter?
>>> On Mon, Feb 9, 2009 at 12:19 AM, Cedric Vivier <cedr...@neonux.com>wrote:
>>>> On Mon, Feb 9, 2009 at 6:05 AM, Thorna <fo...@wanadoo.fr> wrote:
>>>>> Définitely, macros are not for me :-(
>>>>> I don't know if I don't make any effort or if it is a boo-developers-
>>>>> only features or what else, but all the syntax remains
>>>>> incomprehensible for me.
>>>> Even the first `ifdef` example? What don't you get in it?
>>>> You know how Boo transforms source code into assemblies, wrt to macros
>>>> it can be summed up grossly as:
>>>> !) read source code (obviously)
>>>> 2) parses source into an AST representation (a tree of nodes [inheriting
>>>> Node], e.g MethodInvocationExpression)
>>>> 3) expand macro statements (runs the `macro ifdef:` body during
>>>> compilation and replace `ifdef` occurences by the nodes yielded [`yield`
>>>> alone is a shortha nd for yield ifdef.Body])
>>>> 4) expanded AST representation (the one you can see with -p:boo booc
>>>> parameter for instance)
>>>> 5) emit expanded AST into CIL bytecode.
>>>> It can be very useful, not only for implementing linq-style syntax but
>>>> any kind of DSL (e.g Specter), and more generally to shortcut
>>>> long/repetitive code (instead of you writing the code - like `print e` is
>>>> actually a macro that expands to `System.Console.WriteLine(e)` ).
>>>> I'm sure you can find handy usages for this ;-)
>>>> Anyways examples week is not about 'bleeding-edge' macros only, feel
>>>> free to contribute updated/new examples about something else, there is
>>>> plenty of them needing update/cleanup in examples/ ;-)
> On Mon, Feb 9, 2009 at 9:44 PM, Justin Chase <justin.m.ch...@gmail.com>wrote:
>> And a lot of other fun stuff... Is this the best way to submit this code >> or would you rather I formally submit it as a patch or something?
Nice, but after a quick look at the contents of the archive, it looks like most of them are simplified versions of current examples? Or can you tell me which are truly new/different?
That is probably true actually, I think the specter unit tests projects were
not in the original samples and I know I had some trouble getting the
pipeline stuff working due to somethings that had to be done in the project
file. I did tweak things and add some stuff and it is all put together into
one solution which is kind of nice. And I ordered them so that they came in
a gentle logical order to learn about new features.
The BooAndIQuackFu project has an example I created related to using
IQuackFu to explore XML documents. Which is pretty fun.
doc as duck = XmlDocumentFu(xml)
hello = doc.root.h.att.Value
world = doc.root.w.att.Value
On Mon, Feb 9, 2009 at 2:38 PM, Cedric Vivier <cedr...@neonux.com> wrote:
> On Mon, Feb 9, 2009 at 9:44 PM, Justin Chase <justin.m.ch...@gmail.com>wrote:
>>> And a lot of other fun stuff... Is this the best way to submit this code
>>> or would you rather I formally submit it as a patch or something?
> Nice, but after a quick look at the contents of the archive, it looks like
> most of them are simplified versions of current examples?
> Or can you tell me which are truly new/different?