Skip to content

Instantly share code, notes, and snippets.

Nicolas Laurent norswap

Block or report user

Report or block norswap

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@norswap
norswap / why.js
Created Sep 1, 2019
Y Combinator and Trampolines in Javascript
View why.js
const assert = require('assert');
// const is_even = n =>
// (n === 0) || !is_even(n - 1);
const mock_is_even = (myself, n) =>
(n === 0) || !myself(myself, n - 1);
const mockingbird =
fn =>
@norswap
norswap / ! Visitors Comparison
Last active Jul 25, 2019
Visitors Comparison
View ! Visitors Comparison
See https://norswap.com/expression-problem-java/
@norswap
norswap / Visitors.java
Created May 25, 2019
Visitors in Java 8
View Visitors.java
public final class Visitors
{
// ---------------------------------------------------------------------------------------------
// 1. Initial setup.
interface Visitor {
void visit (A object);
void visit (B object);
}
@norswap
norswap / Node.java
Created Sep 13, 2017
Fast Java Reflection
View Node.java
package demo;
public interface Node {}
@norswap
norswap / README.md
Created Feb 10, 2017
Installing SWI-Prolog
View README.md

macOS / OS X

Install homebrew then run brew install swi-prolog. You can now run the Prolog shell from the command line with swipl.

Important: do not install from the official website, you will get crashes.

Windows

View gist:c9ac329bbc745303269ae24a2d3cf53f
### Keybase proof
I hereby claim:
* I am norswap on github.
* I am norswap (https://keybase.io/norswap) on keybase.
* I have a public key whose fingerprint is CB7E 4E0F F8C0 2860 6A62 55F2 A7E2 9E43 45FB 1D8E
To claim this, I am signing this object:
@norswap
norswap / InlineReceiver.kt
Created Nov 8, 2016
Showcasing the usefulness of inline receivers in Kotlin
View InlineReceiver.kt
inline fun <T, U> (() -> T?).map (crossinline f: (T) -> U): (() -> U?)
{
return { this()?.let(f) }
}
inline fun <T> (() -> T?).filter (crossinline pred: (T) -> Boolean): (() -> T?)
{
return {
var out = this()
while (out != null && !pred(out)) out = this()
View virtualbox.md

As VirtualBox Guest

Networking

In the VM properties, make two connections: a "NAT" for regular internet connectivity, and a "host-only" for ssh connectivity between host and guest with a predictable IP. For this to work, both a NAT adapter and a host-only adapter have to be created in the host via the VirtualBox global preferences.

@norswap
norswap / PluginInterface.kt
Created Jan 18, 2016
Plugin Interface Proposal Example for Kotlin
View PluginInterface.kt
// Basic setup
interface Exp
data class Lit(val x: Int): Exp
data class Add(val x: Exp, val y: Exp): Exp
val exp0 = Add(Lit(42), Lit(0x52))
// Adding a print operation
@norswap
norswap / ObjectAlgebra.kt
Created Jan 18, 2016
Object Algebras in Kotlin
View ObjectAlgebra.kt
// Basic setup
interface Exp
data class Lit(val x: Int): Exp
data class Add(val x: Exp, val y: Exp): Exp
interface IntAlg<A>
{
fun lit(x: Int): A
fun add(x: A, y: A): A
You can’t perform that action at this time.