GithubHelp home page GithubHelp logo

objecthub / swift-lispkit Goto Github PK

View Code? Open in Web Editor NEW
364.0 364.0 14.0 22.31 MB

Interpreter framework for Lisp-based extension and scripting languages on macOS and iOS. LispKit is based on the R7RS standard for Scheme. Its compiler generates bytecode for a virtual machine. LispKit is fully implemented in Swift 5.

Home Page: https://lisppad.app

License: Apache License 2.0

Swift 38.71% Objective-C 0.07% Makefile 0.02% Scheme 61.20%
compiler interpreter lisp macos r7rs scheme swift virtual-machine

swift-lispkit's People

Contributors

benkb avatar finestructure avatar objecthub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-lispkit's Issues

How to interact with native Swift libraries?

There is something written in ./Sources/LispKit/Runtime/NativeLibrary.swift

///
/// NativeLibrary defines a framework for defining built-in functionality for LispKit in
/// a modular fashion. Concrete implementations subclass NativeLibrary and override the
/// export method with declarations of constants, procedures, and special forms.
///

But that sounds rather abstract, so I'm not quite sure what this does. The thing I'm looking for is sometimes called 'external symbols' or FFI (foreign function interface) in other languages.

repl: printing without a newline character

In lispkits repl you see no result when displaying without a newline. Comparing with other scheme implementation I prefer one of the following two implementations:

  1. Prefixing it to the next prompt, like for examples Gambit Schemes repl:
> (display "jsd")
jsd>
  1. Pretty printing the (internal) value of side effects like in the Gauche Schemes repl:
gosh> (display "jsd")
jsd#<undef>
gosh>

problem with import

In LispPad.app import do not accept multiple arguments:

➤ (import (lispkit base)(lispkit datatype))
⚠️ 〚argument count error〛 import expects 1 argument, but received 2 arguments: ((lispkit base) (lispkit datatype))

Are you looking for contributions?

@objecthub

I really like this tool. I’m learning a lot, it makes programming fun again, and (for the first time) the iPad is useful for something other than media consumption!

Are you looking for contributions? I can draft some documentation while I learn.

Any place you would like me to start?

Cheers, and thanks.

LispPad, cannot open file '...'

I am completely new to LispPad. I wanted to try PDF generation, and I ran the PDF.scm. It ended with "pdfex4" in the Console, and when I typed pdfex1, I got "#<procedure pdfex1@600000a97b60>", which looks OK to me. However, when I do

(pdfex1 "/Volumes/P3/Lisp/ex1.pdf")

I get this:
cannot open file '/Volumes/P3/Lisp/ex1.pdf'

Why cannot this file be created?

Threads / Concurrency?

First, this looks amazing! Thank you so much for working on this (and releasing it!).

I was curious if any form of threads / concurrency is exposed via lispkit? A quick grep of the codebase only turned up a few DispatchQueue.main.sync calls in Interpreter.

How can I run a script

Hi
Is there a way to invoke .build/debug/LispKitRepl with a <script> argument?
thanks
Ben

Build fails: error: redefinition of module

'swift-lispkit': error: invalidManifestFormat("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/module.modulemap:10:8: error: redefinition of module '_Builtin_intrinsics'\nmodule _Builtin_intrinsics [system] [extern_c] {\n ^\n/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/include/module.modulemap:10:8: note: previously defined here\nmodule _Builtin_intrinsics [system] [extern_c] {\n ^\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/module.modulemap:156:8: error: redefinition of module '_Builtin_stddef_max_align_t'\nmodule _Builtin_stddef_max_align_t [system] [extern_c] {\n ^\n/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/include/module.modulemap:156:8: note: previously defined here\nmodule _Builtin_stddef_max_align_t [system] [extern_c] {\n ^\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/module.modulemap:160:8: error: redefinition of module 'opencl_c'\nmodule opencl_c {\n ^\n/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/include/module.modulemap:160:8: note: previously defined here\nmodule opencl_c {\n ^\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/module.modulemap:10:8: error: redefinition of module '_Builtin_intrinsics'\nmodule _Builtin_intrinsics [system] [extern_c] {\n ^\n/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/include/module.modulemap:10:8: note: previously defined here\nmodule _Builtin_intrinsics [system] [extern_c] {\n ^\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/module.modulemap:156:8: error: redefinition of module '_Builtin_stddef_max_align_t'\nmodule _Builtin_stddef_max_align_t [system] [extern_c] {\n ^\n/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/include/module.modulemap:156:8: note: previously defined here\nmodule _Builtin_stddef_max_align_t [system] [extern_c] {\n ^\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/module.modulemap:160:8: error: redefinition of module 'opencl_c'\nmodule opencl_c {\n ^\n/usr/local/Cellar/llvm/13.0.1_1/lib/clang/13.0.1/include/module.modulemap:160:8: note: previously defined here\nmodule opencl_c {\n ^\n:5:9: note: in file included from :5:\n#import "copyfile.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/copyfile.h:41:9: error: unknown type name 'uint32_t'\ntypedef uint32_t copyfile_flags_t;\n ^\n:5:9: note: in file included from :5:\n#import "copyfile.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/copyfile.h:62:44: error: unknown type name 'uint32_t'\nint copyfile_state_get(copyfile_state_t s, uint32_t flag, void * dst);\n ^\n:5:9: note: in file included from :5:\n#import "copyfile.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/copyfile.h:63:44: error: unknown type name 'uint32_t'\nint copyfile_state_set(copyfile_state_t s, uint32_t flag, const void * src);\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:235:8: error: unknown type name 'intmax_t'\nextern intmax_t\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:236:9: error: unknown type name 'intmax_t'\nimaxabs(intmax_t j);\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:240:2: error: unknown type name 'intmax_t'\n intmax_t quot;\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:241:2: error: unknown type name 'intmax_t'\n intmax_t rem;\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:246:9: error: unknown type name 'intmax_t'\nimaxdiv(intmax_t __numer, intmax_t __denom);\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:246:27: error: unknown type name 'intmax_t'\nimaxdiv(intmax_t __numer, intmax_t __denom);\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:250:8: error: unknown type name 'intmax_t'\nextern intmax_t\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:256:8: error: unknown type name 'uintmax_t'\nextern uintmax_t\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:263:8: error: unknown type name 'intmax_t'\nextern intmax_t\n ^\n:14:9: note: in file included from :14:\n#import "inttypes.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/inttypes.h:269:8: error: unknown type name 'uintmax_t'\nextern uintmax_t\n ^\n:23:9: note: in file included from :23:\n#import "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/stdatomic.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/stdatomic.h:93:17: error: unknown type name 'uint_least16_t'\ntypedef _Atomic(uint_least16_t) atomic_char16_t;\n ^\n:23:9: note: in file included from :23:\n#import "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/stdatomic.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/stdatomic.h:94:17: error: unknown type name 'uint_least32_t'\ntypedef _Atomic(uint_least32_t) atomic_char32_t;\n ^\n:23:9: note: in file included from :23:\n#import "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/stdatomic.h"\n ^\n/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/stdatomic.h:96:17: error: unknown type name 'int_least8_t'\ntypedef _Atomic(int_least8_t) atomic_int_least8_t;\n ^\n:0: error: too many errors emitted, stopping now\n:0: error: could not build Objective-C module 'Darwin'\n/Volumes/scand500gb01/usrdirs_bkb_drive_scand500gb01/localstore_bkb_drive_scand500gb01/dev_homefolders/local/lispkit/swift-lispkit.git/Package.swift:39:8: error: failed to build module 'PackageDescription' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug\nimport PackageDescription\n ^", diagnosticFile: nil)

repl: text formatting (color)

Not sure if this is a bug, but for me it is unexpected and not ideal behaviour:

The output of the repl is formatted dark. I don't think it matches any of the terminal emulators (iTerm.app, Terminal.app) font color presets.

So if I open the repl in my dark background terminal I don't see the prompt of the repl. Similarly I don't see any of the output of the evaluated expressions.

problem with sort

sort do not conform to srfi-95.

now is: (sort < list)
should be: (sort list <)

bytevector-copy returns range error with less than three arguments

The bytevector-copy function always expects three arguments, instead of allowing the last two to be optional. I'm using bytevectors a lot in an application, and it is convenient to pull sections out of them using the 2-argument version, so I happened to notice this. Unless I've completely misunderstood something, then it works different than the documentation.

From LispPad Reference 1.7:

Returns a newly allocated bytevector containing the bytes in bytevector between start and end. If end is not provided, it is assumed to be the length of bytevector. If start is not provided, it is assumed to be 0.

However, in LispPad 1.72 on macOS, both the 1-argument and 2-argument versions give range error:

➤ a
#u8(1 2 3 4 5)
➤ (bytevector-copy a)
⚠️ 〚range error〛 expected argument 2 of function bytevector-copy to be an integer value within the range [0, 4]; is 5 instead
└── (bytevector-copy …) « ( …)
➤ (bytevector-copy a 1)
⚠️ 〚range error〛 expected argument 3 of function bytevector-copy to be an integer value within the range [1, 5]; is 0 instead
└── (bytevector-copy …) « ( …)
➤ (bytevector-copy a 1 4)
#u8(2 3 4)

I looked at the source code, and I'm not sure I know what is happening to make a pull request, but maybe this turns out to be a quick fix for you.

The LispKit documentation agrees with R7RS, but SRFI 66 doesn't seem to have byte-vector-copy with up to three arguments.

Possible workaround: compute desired length and index, then use the 3-argument version.

`(lispkit math)` truncation procedures do not guard against zero divisor

Unlike division, implementations of the truncation procedures in (lispkit math) (such as truncate-remainder) do not guard against the divisor (n2) being zero, and this causes LispPad to crash when the procedure is evaluated.

How to reproduce:

➤ (/ 2 0) ; ⚠️ 〚eval error〛 division by zero
➤ (truncate-remainder 2 0) ; app crashes

Happy to attempt a PR but I reckon my Swift is good enough to find the problem, but not good enough to come up with an elegant solution!

PS: Thank you so much for building software that has brought me so much joy ❤️ Never thought I'd be writing Lisp on the couch on my iPad!

Unable to build from command line

Using Xcode 14.2 in macOS Monterey 12.6.4, I can build the LispKitREPL scheme just fine, but building from command line fails.

There are a couple of dozen errors, and they all seem to be related to availability of APIs.

Example of the output from make repl in Terminal, after the dependencies have been fetched and built:

Building for production...
/Users/jerekapyaho/Projects/swift-lispkit/Sources/LispKit/Base/Data.swift:27:12: error: 'init(unsafeUninitializedCapacity:initializingUTF8With:)' is only available in macOS 11.0 or newer
    return String(unsafeUninitializedCapacity: 2 * self.count) { (ptr) -> Int in
           ^
/Users/jerekapyaho/Projects/swift-lispkit/Sources/LispKit/Base/Data.swift:27:12: note: add 'if #available' version check
    return String(unsafeUninitializedCapacity: 2 * self.count) { (ptr) -> Int in
           ^
/Users/jerekapyaho/Projects/swift-lispkit/Sources/LispKit/Base/Data.swift:25:8: note: add @available attribute to enclosing instance method
  func hexEncodedString(upperCase: Bool = false) -> String {
       ^
/Users/jerekapyaho/Projects/swift-lispkit/Sources/LispKit/Base/Data.swift:23:1: note: add @available attribute to enclosing extension
extension Data {
^
/Users/jerekapyaho/Projects/swift-lispkit/Sources/LispKit/Primitives/CryptoLibrary.swift:150:47: warning: conformance of 'Insecure.MD5Digest' to 'Sequence' is only available in macOS 10.15 or newer
    return BytevectorLibrary.bytevector(from: Data(Insecure.MD5.hash(data: Data(subvec))))
                                              ^
/Users/jerekapyaho/Projects/swift-lispkit/Sources/LispKit/Primitives/CryptoLibrary.swift:150:47: note: add 'if #available' version check
    return BytevectorLibrary.bytevector(from: Data(Insecure.MD5.hash(data: Data(subvec))))
                                              ^
/Users/jerekapyaho/Projects/swift-lispkit/Sources/LispKit/Primitives/CryptoLibrary.swift:148:16: note: add @available attribute to enclosing instance method
  private func md5(expr: Expr, args: Arguments) throws -> Expr {
               ^

...and so on. make clean does not change the situation.

It almost looks like I was on macOS 10.14 or older, but this is Monterey with the latest security updates as of 2023-03-29. Latest repository updates from master are included (commit 506e9199f5a295a934c7463b49bd0add31d39869)

I can't see anything obviously wrong with my Xcode installation, since the LispKitREPL scheme and also other macOS and iOS applications can be built. It's just the command line that is failing. Any idea what might be causing this?

Calling iOS SDKs

First, congratulation for your work ! It's quite amazing.
I am thinking myself about making a small lisp compiler or interpreter and your project helps a lot.

I'd like to know if it's possible to import and call iOS SDKs ?
If so, how did you manage to do it ?

Thanks a lot !
Baptiste

LispPad 1.2.2, included documentation?

When I upgraded LispPad in App Store, to version 1.2.2, I noticed the version info said "now includes the documentation announced already for version 1.2.1". Where can this documentation be found?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.