Skip to content

Instantly share code, notes, and snippets.

View rsimoes's full-sized avatar

Richard Simões rsimoes

  • Center for Technology and Civic Life
  • Austin, Texas
View GitHub Profile
@rsimoes
rsimoes / mymap.pl
Created December 27, 2011 01:51 — forked from gatlin/mymap.pl
Functional definition of map in Perl
#!/usr/bin/env perl
use strict;
use warnings;
sub myMap(&@) {
!wantarray && @_ - 1 || @_ > 1 && (
do {
local $_ = $_[1];
$_[0]->();
@rsimoes
rsimoes / uni_charassign.dats
Created December 13, 2011 09:30
unicode character assignment in ATS
val foo = '€';
implement main () = ()
(*
rsimoes@desktop:~/scratch/ats$ atscc uni_charsassign.dats
/usr/lib/ats-anairiats-0.2.5/bin/atsopt --output uni_charsassign_dats.c --dynamic uni_charsassign.dats
/home/rsimoes/scratch/ats/uni_charsassign.dats: LEXING ERROR: illegal character at [11(line=1, offs=11)] is unclosed!
exit(ATS): uncaught exception: _2fhome_2ffac2_2fhwxi_2fresearch_2fATS_2fIMPLEMENT_2fGeizella_2fAnairiats_2fsvn_2fats_2dlang_2fsrc_2flibats_lex_lexing_2esats__LexingErrorException(1235)
exit(ATS): [ccomp_file_to_file(uni_charsassign.dats, uni_charsassign_dats.c)] failed
*)
@rsimoes
rsimoes / uni_stringlen.dats
Created December 13, 2011 09:23
unicode string-length measuring in ATS
fun string_length {n:nat}
(str: string n): size_t n = let
fun loop {i:nat | i <= n}
(str: string n, i: size_t i): size_t (n) =
if string_isnot_at_end (str, i) then loop (str, i+1) else i
in
loop (str, 0)
end
implement main () = begin
use strict;
use warnings;
use Coro;
my $offset = 0;
my $inc = 100;
my $max = 6;
my @coros;
my $stdout = "Incrementing \$offset by $inc...\n---\n";
@rsimoes
rsimoes / js.pl
Created November 26, 2011 02:52
javascript in perl
use strict;
use warnings;
use subs::auto;
my %vars;
sub var (*) :lvalue {
my $var = shift;
no strict 'refs';
no warnings 'redefine';
*{$var} = sub { (\%vars)->{$var}; };
@rsimoes
rsimoes / autobox_bless.pl
Created November 18, 2011 08:21
Misusing autobox to manually box non-refs
#!/usr/bin/env perl
use strict;
use warnings;
use autobox;
package A;
sub call { print "A!\n" }