Skip to content

Instantly share code, notes, and snippets.

@javipus
Created February 13, 2020 20:27
Show Gist options
  • Save javipus/01bfba84ffbf2e18808de3a6838d49a0 to your computer and use it in GitHub Desktop.
Save javipus/01bfba84ffbf2e18808de3a6838d49a0 to your computer and use it in GitHub Desktop.
% Prolog translation of the key functions in
% https://github.com/nearai/program_synthesis/blob/master/program_synthesis/algolisp/dataset/code_lisp.py
:- use_module(library(lists)).
:- use_module(library(dicts)).
% if ???
% if(context, cond, then, else).
% get Index-th element in list - alias of nth0 from lists library
deref(Index, List, Elem) :- nth0(Index, List, Elem).
% set dict[key] to value - alias of put_dict from dicts library
dict_insert(Key, DictIn, Value, DictOut) :- put_dict(Key, DictIn, Value, DictOut).
% get head of list
head([H|_], H).
% integer range
% see https://stackoverflow.com/questions/7175258/prolog-generating-numbers-fitting-given-range
range_func(Lo, Lo, _).
range_func(Out, Lo, Hi) :- NewLo is Lo+1, range_func(Out, NewLo, Hi).
% reduce
% ???
% partial
% ???
% lambdas ???
% div
div(X, Y, X_div_Y) :- X_div_Y is X/Y.
% slice
% could use this implementation or produce my own
% https://github.com/stassa/indexed_terms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment