# Another R bridge

**URL:** <https://swi-prolog.discourse.group/t/another-r-bridge/4144>\
**Category:** Announce\
**Created:** [July 8, 2021, 6:25pm UTC](https://swi-prolog.discourse.group/t/another-r-bridge/4144 "2021-07-08T18:25:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgondan1](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mgondan1/32/803_2.png) [@mgondan1](https://swi-prolog.discourse.group/u/mgondan1)\
**Post date:** [July 8, 2021, 6:26pm UTC](https://swi-prolog.discourse.group/t/another-r-bridge/4144/1 "2021-07-08T18:26:00Z")

</div>

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:

> **[mgondan/rolog](https://github.com/mgondan/rolog)**
>
> Access SWI-Prolog from R. Contribute to mgondan/rolog development by creating an account on GitHub.

```prolog
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 ☹ [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
