Another R bridge

Dear friends,

I am so proud! This is another bridge between SWI-Prolog and R, but in contrast to Real or rserve_client, this one works both ways, even simultaneously:

library(rolog)

# first solution of member(X, [1, 2, 3])
rolog_once(call("member", expression(X), list(1, 2, 3)))
$X
[1] 1

# all solutions
rolog_findall(call("member", expression(X), list(1, 2, 3)))
[[1]]
[[1]]$X
[1] 1

[[2]]
[[2]]$X
[1] 2

[[3]]
[[3]]$X
[1] 3

# Define custom function in R
my_rnorm = rnorm

# Call R from Prolog
rolog_once(quote(use_module(library(rologpp))))

# Back and forth
rolog_once(call("r_eval", call("my_rnorm", 3), expression(X)))
$X
`#`(0.201164670227115, -1.28030023334362, 0.262585543239151)

It’s still at an alpha stage:

  • complicated installation
  • cumbersome syntax. expression(X) is misused for declaring X a variable, and you have to “quote” and “call” a lot on the R side.
  • no cyclic terms
  • debug output cluttering the screen
  • no tests yet
  • quite a few places in the code which are unnecessarily complicated
  • and I am sure it is easily crashed by experienced hackers
  • no proper use case :frowning: [well, let’s see, maybe someone finds good use for it]
  • no Mac support because I don’t have one to test it there
  • despite programmation en logique being a museum language, there’s not even support for 32-bit R

So any hints for improvement are very much appreciated.

Best wishes

Matthias

3 Likes