Skip to content

Instantly share code, notes, and snippets.

{
"metadata":{
"position":1685,
"type":"BufferGeometry",
"normal":1685,
"uv":1685,
"generator":"io_three",
"version":3
},
"data":{
@grondilu
grondilu / Algebra.pm6
Last active September 20, 2017 20:15
unit role Algebra;
proto method ADD($) {*}
multi method ADD(Real $) {...}
multi method ADD(::?CLASS $) {...}
proto method MULTIPLY($) {*}
multi method MULTIPLY(::?CLASS $) {...}
multi method MULTIPLY(Real $) {...}

\begin{align*} \epsilon_{\mu\nu\alpha\beta}\epsilon^{\alpha\beta\gamma\sigma} \partial_\gamma\partial^\nu \frac{|x|}{(k\cdot x)^2} &=\epsilon_{\mu\nu\alpha\beta}\epsilon^{\alpha\beta\gamma\sigma} \partial_\gamma\partial^\nu \frac{|x|}{(k\cdot x)^2}\ &=\epsilon_{\mu\nu\alpha\beta}\epsilon^{\alpha\beta\gamma\sigma} \partial_\gamma \left(

# https://en.wikipedia.org/wiki/Parsing_expression_grammar
grammar Arithmetic {
rule TOP { ^^ <Exp> $$ }
rule Exp { <Sum> }
rule Sum { <Product>+ % <[+-]> }
rule Product { <Value>+ % <[*/]> }
rule Value { <ident>+ | '('<Exp>')' }
}
say Arithmetic.parse($_) for
# inspired from L<http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm>
grammar Algebra {
rule TOP { ^^<e>$$ }
token e { <t>+ % <[+-]> }
token t { <f>+ % <[*/]> }
token f { <p>[\^<f>]? }
token p { <v> | \(<e>\) | \-<t> }
token v { <ident> | <number> }
token number { <.integer><.fraction>? }
grammar Algebra {
rule TOP { ^^ <expression> $$ }
rule expression { <+symbol+sum+product> }
rule sum {
| <symbol>\+<expression>
}
rule product {
| <symbol>\*<symbol>
| <symbol>\*\(<sum>\)
@grondilu
grondilu / gist:83dfb2046ea7a6f3313152c77342559e
Created October 3, 2016 15:18
testing syntax highlighting
```C
#inclde <stdio.h>
int main(int argc, char* argv[])
printf("Hello, world!\n");
}
```
=begin comment
In this grammar, <expression> loops endlessly when tried with an empty string.
It first fails at <variable>, which is fine, it then fails at <function> which is also fine,
but then it keeps trying <application> recursively, even if <application> contains
at least the characters '(' and ')'.
Shouldn't Perl 6 be smart enough to understand that <application> will never match with an empty string?
=end comment
say grammar {
@grondilu
grondilu / gist:88f009105383b9c675d5702a489fa6b8
Last active October 1, 2016 11:59
can a compiler be made as a chain of sub-compilers?
It is known that functional programming and -at the extreme- lambda-calculus is fundamentally equivalent to more conventional programming, involving sequential execution of statements and variable affectation.
For instance a code like:
my $x = foo();
bar($x);
fiz($x);
can be written:
@grondilu
grondilu / nativeCall-use-with-structured-types.md
Last active August 29, 2016 17:34
example of NativeCall use

Here is a basic point type in C:

#include <stdlib.h>

struct point_t {
    double x;
    double y;
};

typedef struct point_t* point;