Skip to content

Instantly share code, notes, and snippets.

  • Create a Species model with just id and name columns
  • Create a Mon model inheriting from Account with just additional owner and species relationships
    • Create a migration which adds a type column defaulting to "Account" to the accounts table
    • Add a validation to Mon requiring that the user be nil.
  • Add a validation to Mon requiring that the owner must not be a Mon.
@ekiru
ekiru / gist:902605
Created April 4, 2011 22:28
An example of C error handling with goto.
int main(int argc, char **argv) {
foo_error error;
foo_bar bar;
error_init(&error);
if (!foo_init(&error))
goto foo_init_error;
if (!foo_bar_init(&bar, "baz", &error))
use v6;
sub with-attributes ($obj, *&callback) {
my %slot-values;
for &callback.signature.params -> $param {
my $slot = $param.name.substr(1);
%slot-values{$slot} = $obj."$slot"();
}
callback |%slot-values;
}
Copyright 2010. <SOMETHING>
This module is free software; you can
redistribute it and/or modify it under the terms of the Artistic
License 2.0. For details, see the full text of the license in the file
LICENSE.
This program is distributed in the hope that it will be useful, but it
is provided “as is” and without any express or implied warranties. For
details, see the full text of the license in the file LICENSE.
(define (fib n k)
(cps-if (= n 1)
(lambda () ; base case
(k 1))
(lambda () ; non-base case
(fib (- n 1)
(lambda (fib-n-1)
(fib (- n 2)
(lambda (fib-n-2)
(k (+ fib-n-1 fib-n-2)))))))))
use v6;
my $xml = '
<test>test</test>
<hat test="20"> hat text here </hat>
<shoe>
<test>asdf</test>
<test>asdf2</test>
<test>asdf3</test>
<test>asdf4</test>
%obj = type opaque*
declare void @bennu_init()
declare %obj @bennu_int_new (i32)
declare %obj @bennu_say (%obj)
define i32 @main () {
call void @bennu_init()
%__local_0 = call %obj @bennu_int_new(i32 42)
%a = %obj %__local_0
%__local_1 = %obj %a
declare i32 @printf (i8*, ...)
@INTPRINTF = internal constant [4 x i8] c"%d\0A\00"
define i32 @main () {
%__local_0 = add i32 0, 42
%__temp_0 = getelementptr [04 x i8]* @INTPRINTF, i64 0, i64 0
call i32 (i8, ...)* @printf(i8* %__temp_0, i32 %__local_0)
ret i32 0
}
What I did:
All of the following except where specified otherwise are referring to the gsoc_past_optimization branch.
* Implemented capturing of child and attribute sub-patterns of PAST::Patterns.
* Added .match and .subst methods to PAST::Node when PAST/Pattern.pbc is loaded.
* Implemented :g/:global and :p/:pos attributes for matching PAST::Patterns.
role FoldArithmetic::Actions does PAST::Optimization::Actions {
method foldAdd($/) {
my ($left, $right) := $<PAST::Val>;
my $result := PAST::Val.new(:value(pir::add($left.value(), $right.value())));
make $result;
}
}