Skip to content

Instantly share code, notes, and snippets.

View pnkfelix's full-sized avatar
🍩
re-pat; ex-🥐

Felix S Klock II pnkfelix

🍩
re-pat; ex-🥐
View GitHub Profile
@pnkfelix
pnkfelix / gist:5503376
Created May 2, 2013 16:24
Attempting to encode a nested (aka "non-regular", "non-uniform") data type in Rust.
enum Seq<A> {
Nil,
Cons{hd: A, tl:~Seq<(A,A)>}
}
impl<A> Seq<A> {
fn len(&self) -> int {
match self {
&Nil => 0,
&Cons{ hd: x, tl: ref s } => 1 + 2 * s.len()
@pnkfelix
pnkfelix / Makefile
Last active December 17, 2015 21:19
one:
touch one
two:
false
clean:
rm one
@pnkfelix
pnkfelix / gist:5774094
Created June 13, 2013 14:27
why is lint saying this `unsafe` is unnecessary? There is a deref of a *ptr ...
/Users/fklock/Dev/Mozilla/rust.git/src/libstd/pipes.rs:106:21: 106:69 warning: unnecessary `unsafe` block [-W unused-unsafe (default)]
/Users/fklock/Dev/Mozilla/rust.git/src/libstd/pipes.rs:106 { $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/fklock/Dev/Mozilla/rust.git/src/libstd/pipes.rs:105:0: 107:1 note: in expansion of move_it!
/Users/fklock/Dev/Mozilla/rust.git/src/libstd/pipes.rs:321:24: 321:46 note: expansion site
/Users/fklock/Dev/Mozilla/rust.git/src/libstd/os.rs:962:12: 968:13 warning: unnecessary `unsafe` block [-W unused-unsafe (default)]
/Users/fklock/Dev/Mozilla/rust.git/src/libstd/os.rs:962 unsafe {
/Users/fklock/Dev/Mozilla/rust.git/src/libstd/os.rs:963 if do str::as_c_str(to.to_str()) |to_buf| {
/Users/fklock/Dev/Mozilla/rust.git/src/libstd/os.rs:964 libc::chmod(to_buf, from_mode as mode_
@pnkfelix
pnkfelix / gist:5798282
Created June 17, 2013 16:40
OS X, custom-installed nspr (in ~/opt/nspr/...) and brew-installed nspr (in /usr/local/...) error
% LD_LIBRARY_PATH=~/opt/nspr/lib /Users/pnkfelix/Dev/Mozilla/iontrail-tests/objdir-dbg-js/js -f /Users/pnkfelix/Dev/Mozilla/iontrail-tests/js/src/jit-test/lib/prolog.js -e "const platform='darwin'; const libdir='/Users/pnkfelix/Dev/Mozilla/iontrail-tests/js/src/jit-test/lib/'; const scriptdir='/Users/pnkfelix/Dev/Mozilla/iontrail-tests/js/src/jit-test/tests/parallelarray/'" -f /Users/pnkfelix/Dev/Mozilla/iontrail-tests/js/src/jit-test/tests/parallelarray/alloc-array.js
dyld: Library not loaded: @executable_path/libplds4.dylib
Referenced from: /Users/pnkfelix/Dev/Mozilla/iontrail-tests/objdir-dbg-js/js
Reason: no suitable image found. Did find:
/usr/local/lib/libplds4.dylib: mach-o, but wrong architecture
Trace/BPT trap: 5
@pnkfelix
pnkfelix / play-tt-parse1.rs
Last active December 18, 2015 21:49
Rightward-drifting macro expression, 2880 occurrences of macro m!
macro_rules! m(
($e1:expr @ $e2:expr) => ({ $e1 })
)
fn main() {
let _x =
m!(11 @ m!(12 @ m!(13 @ m!(14 @ m!(15 @ m!(16 @ m!(17 @ m!(18 @ m!(19 @
m!(21 @ m!(22 @ m!(23 @ m!(24 @ m!(25 @ m!(26 @ m!(27 @ m!(28 @ m!(29 @
m!(31 @ m!(32 @ m!(33 @ m!(34 @ m!(35 @ m!(36 @ m!(37 @ m!(38 @ m!(39 @
m!(41 @ m!(42 @ m!(43 @ m!(44 @ m!(45 @ m!(46 @ m!(47 @ m!(48 @ m!(49 @
trait A { fn foo(&self); }
trait B<X:A> { fn bar(&self, @X); }
trait C<X:A, Y:B<X>> { fn baz(&self, @X, @Y); }
// This doesn't work, as trait bounds are not allowed in structure defn's.x
// struct Cat<X:A, Y:B<X>> { x: @X, y: @Y }
// Workaround by putting the check elsewhere
struct Cat<X, Y> { x: @X, y: @Y }
struct S { x: int }
impl S {
fn f(self) {
let mut ms = self;
println(fmt!("self pre: %? ms pre: %?", self, ms));
ms.x = 4;
println(fmt!("self post: %? ms post: %?", self, ms));
}
}
% rustc /tmp/toksize.rs && /tmp/toksize
warning: no debug symbols in executable (-arch x86_64)
size_of(Token): 192
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-*- mode: compilation; default-directory: "~/Dev/RustVisitParam/rust1.git/objdir-dbgopt/" -*-
Compilation started at Tue Aug 13 18:57:16
time remake -j8
cfg: build triple x86_64-apple-darwin
cfg: host triples x86_64-apple-darwin
cfg: target triples x86_64-apple-darwin
cfg: enabling more debugging (CFG_ENABLE_DEBUG)
cfg: host for x86_64-apple-darwin is x86_64
cfg: os for x86_64-apple-darwin is apple-darwin