Skip to content

Instantly share code, notes, and snippets.

View fracek's full-sized avatar
🎯
Focusing

Francesco Ceccon fracek

🎯
Focusing
View GitHub Profile

Keybase proof

I hereby claim:

  • I am fracek on github.
  • I am fracek (https://keybase.io/fracek) on keybase.
  • I have a public key ASBNKBl-C187AH5zntexFUUJ9hGGF3DsoTx6KSeVsu5vFAo

To claim this, I am signing this object:

proc (1) = minpr(x);
local d,m,i,minx;
i = 1;
m = 1;
d = x[1];
do while i <= rows(x);
if x[i] < d;
d = x[i];
endif;
# -*- coding: utf-8 -*-
# Fetch Barterzzaghi crosswords
import datetime
import os
import requests
import sys
import xml.etree.ElementTree as ET
URL = 'http://www.repubblica.it/static/rubriche/ilcruciverba/{0}/{1}.js'

This week in an effort to make the bindings generated by Melange more idiomatic, I hacked on Dylan's c-ffi library.

Many C libraries use the function return value to signal an error occurred, but in Dylan this is unnecessary because we have support for error conditions and exception handling.

Using libgit2 as an example, before my changes we had to either:

define class <libgit2-error> (<error>)
constant slot libgit2-error-status :: <integer>, required-init-keyword: status:;
constant slot libgit2-error-message :: <string>, init-keyword: message:, init-value: "Unknown error";
end;
define C-mapped-subtype <libgit2-status> (<C-int>)
import-map <integer>,
import-function:
method (result :: <integer>) => (checked :: <integer>)
if (result < 0)
define git-options <git-clone-options*>
option git-clone-options$version => version;
option git-clone-options$checkout-opts => checkout-options;
option git-clone-options$remote-callbacks => remote-callbacks;
option git-clone-options$bare => bare?;
option git-clone-options$ignore-cert-errors => ignore-cert-errors;
option git-clone-options$local => local?;
option git-clone-options$remote-name => remote-name;
option git-clone-options$checkout-branch => checkout-branch;
define git-options <git-repository-init-options*>
option git-repository-init-options$version => version = 1;
option git-repository-init-options$flags => flags;
option git-repository-init-options$mode => mode;
option git-repository-init-options$workdir-path => working-directory;
option git-repository-init-options$description => description;
option git-repository-init-options$template-path => template-path;
option git-repository-init-options$initial-head => initial-head;
option git-repository-init-options$origin-url => origin-url;
define traced macro gen-bind
{ gen-bind(?:name; ?identifier:name => ?dylan-identifier:name ?:*) }
=> { if (?dylan-identifier)
//?name ## "$" ## ?identifier ## "-setter"(?dylan-identifier, opts);
format-out("DYLAN %=\n", ?dylan-identifier);
end if }
{ gen-bind(?:name; ?identifier:name ?:*) }
=> { if (?identifier)
//?name ## "$" ## ?identifier ## "-setter"(?identifier, opts);
format-out("YYY %=\n", ?identifier);
define macro gen-bindings
{ gen-bindings(?:name; ?flags) }
=> { ?flags }
flags:
{ }
=> { }
{ ?flag, ... }
=> { ?flag; ... }
define method initialize(opts :: <git-repository-init-options*>,
#key version = 1,
flags = #f,
mode = #f,
working-directory = #f,
description = #f,
...
origin-url = #f)
if (version)
git-repository-init-options$version(opts) := version;