Posts tagged racket

config racket/rsvg lib to use librsvg via FFI in Racket

:: racket, ffi

By: Alex-1Q84

I have a little Racket program that dependences racket/rsvg, so I install the racket/rsvg lib on my macOS using under command

raco pkg install -u rsvg

but when I then run the program, it produces some error messages

ffi-lib: couldn’t open “librsvg–2.2.dylib” (dlopen(librsvg–2.2.dylib, 6): image not found)

after check the racket’s ffi-lib doc, I fixed it, the follow is How I fix the problem. originally posted on github

I have the same problem, and when I checked the method ffi-lib doc, it explains how racket finds ffi lib path

If path is not an absolute path, look in each directory reported by get-lib-dirs; the default list is the result of (get-lib-search-dirs).

as the racket document describes, we can use the code under here to get the current lib search dirs

(require setup/dirs)
(get-lib-search-dirs)

on my computer the result is '(#<path:/Users/mywo/Library/Racket/7.9/lib> #<path:/usr/local/opt/Racket/lib>). and my librsvg lib path is /usr/local/Cellar/librsvg/2.48.8/lib/librsvg-2.2.dylib, which can find with homebrew

brew list librsvg

if you don’t have librsvg in you system, you can install it using Homebrew

brew install librsvg

the racket document shows we can config lib search dirs, follow the Installation Configuration and Search Paths I changed my racket config file /Applications/Racket v7.9/etc/config.rktd, add the 'lib-search-dirs' setting to it, and my program running correctly.

here is my config.rktd content

#hash((build-stamp . "")
      (catalogs . ("https://download.racket-lang.org/releases/7.9/catalog/" #f))
      (doc-search-url . "https://download.racket-lang.org/releases/7.9/doc/local-redirect/index.html")
      (lib-search-dirs . ("/usr/local/opt/librsvg/lib/" #f)))

racket ffi 使用相关说明

  • http://prl.ccs.neu.edu/blog/2016/06/27/tutorial-using-racket-s-ffi/
  • http://prl.ccs.neu.edu/blog/2016/06/29/tutorial-racket-ffi-part–2/
  • http://prl.ccs.neu.edu/blog/2016/07/11/tutorial-racket-ffi-part–3/

学习 Racket 语言

:: racket, learn, function progamming

By: Alex-1Q84

1. 最重要的事情是练习练习练习

一开始可以跟着 ANSI Common Lisp 这本书做练习,前七章非常好,内容基本可以套用到 racket 上。已经有热心人翻译成中文了。这是 Common Lisp 的文档,对照阅读出现语法理解问题时可以使用。

2. 更多练习

可以使用 Realm of Racket 这本书,跟着书抄代码,做做 challenges 。这本书跟 How to Design Programs, Second Edition (后面简称 2htdp)这本书有很大关系,许多例子是基于 2htdp 所提供的工具包实现的,学习的时候可以顺便看看 2htdp 的工具包文档说明,DrRacket 自带了这部分说明文档,练习时可以方便地查看。Realm of Racket 这本书是收费的,质量非常不错,虽然对于国内来说价格略贵,建议用起来感动的话还是用实际行动支持下作者。

3. 进阶

跟着 Beautiful Racket 学习 racket 强大的宏系统。

4. 有经验的程序员

对于有经验的程序员,可以从 racket 自带的 《More: Systems Programming with Racket》入手,在 racket 自带文档中搜索即可看到。跟着这个教程抄一遍代码是个很好的路子,可以作为使用 racket 快速上手做一些实际的事情的入口,抄完这个代码可以通过这个页面的链接做一些扩展了解。

5. 其他

另找到一本 racket 入门练习书 Picturing Programs: an Introduction to Computer Programming ,和 2htdp 也有莫大渊源,这本书可以免费获取,或许可以作为 Realm of Racket 的替代品(不负责任),合适的话也请赞助作者。

附上 Racket 和 Common Lisp 的语法介绍,练习时可以对照感受下异同 Racket Common Lisp