Table of Contents
This is a simplified version of my previous proposal, here: https://gist.github.com/Timbus/1f278441e7ecffbb67b664a49e18adcb
This is a simplified version of my previous proposal, here: https://gist.github.com/Timbus/1f278441e7ecffbb67b664a49e18adcb
With this document I propose two new features that work together to provide lexically scoped "extension methods" to crystal objects, with the intent of providing a safer, cleaner way to both create and use libraries.
I define "extension methods" as methods that don’t (typically) modify the state of the object they are
require "openssl" | |
require "socket" | |
server = TCPServer.new("localhost", 3900) | |
certfile = "cert.pem" | |
keyfile = "key.pem" | |
unless File.exists?(certfile) && File.exists?(keyfile) | |
openssl_params = [ |
sub primes-sieve3(Int $max) { | |
my int @sieve; | |
my int $effective-max = ($max-1) div 2; | |
lazy gather for 1 .. $effective-max -> int $i { | |
FIRST take 2; | |
next if @sieve[$i]; | |
my int $prime = 2 * $i + 1; | |
take $prime; | |
my $fill-range = ($effective-max - $i) div $prime; | |
for 1 .. $fill-range -> int $j { |
<? | |
$doc = new DOMDocument; | |
$doc->loadHTML(file_get_contents("http://radio.7chan.org:8000/status.xsl")); | |
$xp = new DOMXpath($doc); | |
$nl = $xp->query("//div[@class='streamheader'][table[1]//h3 = 'Mount Point /radio']/following-sibling::table//tr[td = 'Content Type:']/td[@class='streamdata']/text()"); | |
echo $nl->item(0)->textContent; |
class My::Model { | |
use GTKBind::Model; | |
attach 'text' => ( | |
to => [ 'entry', 'label' ], | |
default => 'derp', | |
); | |
attach 'reset_active' => ( | |
to => { id => 'resetbutton', property => 'sensitive' }, |
{ package Late; | |
use Moose (); | |
use Moose::Exporter; | |
Moose::Exporter->setup_import_methods( | |
class_metaroles => { | |
class => ['Late::MetaRole::Class'], | |
attribute => ['Late::MetaRole::Attribute'], | |
}, | |
); | |
1;} |
my @q; | |
sub async(&f){ | |
push @q, $(gather {f({take $_})} ) | |
}; | |
sub yield { | |
for @q -> $l { | |
push @q, $l if $l.shift | |
} | |
} |
class IO::Socket::INET2 does IO::Socket { | |
has $.peeraddr; | |
has $.peerport = 80; | |
has $.localaddr; | |
has $.localport; | |
has $.listen; | |
has $.proto = PIO::PROTO_TCP; | |
has $.type = PIO::SOCK_STREAM; | |
method new (*%args is copy) { |
#!/usr/bin/perl | |
use strict; | |
my $name = "EvalScript"; | |
my $version = '0.1'; | |
Xchat::register($name, $version); | |
Xchat::print "$name version $version loaded\n"; | |
my $__evalerror = 1; | |
my ($a, $b, @arr, %hash); |