Skip to content

Allow compiling standard sources#1684

Merged
alexarchambault merged 3 commits into
com-lihaoyi:mainfrom
alexarchambault:allow-compiling-standard-files
Oct 8, 2025
Merged

Allow compiling standard sources#1684
alexarchambault merged 3 commits into
com-lihaoyi:mainfrom
alexarchambault:allow-compiling-standard-files

Conversation

@alexarchambault

@alexarchambault alexarchambault commented Oct 6, 2025

Copy link
Copy Markdown
Collaborator

This adds the ability to supply "raw sources" during an Ammonite session, like

@ package thing

  object Thing {
    def message = "Hello"
  }


@ thing.Thing.message
res1: String = "Hello"

Input code starting with package is assumed to be a raw source. It must end with two empty lines (the input parser stops expecting more input when it gets two empty lines in a row).

This is a somewhat quick-and-dirty, yet handy way for users to import simple sources in Ammonite (and this should be handy in Almond too). This can also be helpful to work around issues that can arise because of code wrapping.

@alexarchambault alexarchambault force-pushed the allow-compiling-standard-files branch 2 times, most recently from 7c4f9dc to 01d9c45 Compare October 7, 2025 11:24
@alexarchambault alexarchambault marked this pull request as ready for review October 7, 2025 11:25
@alexarchambault alexarchambault force-pushed the allow-compiling-standard-files branch 2 times, most recently from 3f3a159 to 70b8bcf Compare October 7, 2025 13:00
@alexarchambault alexarchambault changed the title Allow compiling standard files Allow compiling standard sources Oct 7, 2025
@alexarchambault alexarchambault force-pushed the allow-compiling-standard-files branch 2 times, most recently from 9ec6d1e to 8395604 Compare October 7, 2025 13:06
@alexarchambault

Copy link
Copy Markdown
Collaborator Author

@lihaoyi @lefou Do you have an opinion about that feature and those changes?

@lihaoyi

lihaoyi commented Oct 7, 2025

Copy link
Copy Markdown
Member

@alexarchambault no opinion, looks great i think

@alexarchambault alexarchambault force-pushed the allow-compiling-standard-files branch from 8395604 to b66a6ca Compare October 8, 2025 10:41
@alexarchambault alexarchambault merged commit a2633b4 into com-lihaoyi:main Oct 8, 2025
13 checks passed
@alexarchambault alexarchambault deleted the allow-compiling-standard-files branch October 8, 2025 13:13
@mullerhai

Copy link
Copy Markdown

Hi @alexarchambault ,very thanks for use almond.sh . now I could use almond.sh scala3.6.3 kernel to write pytorch
coda on scala3 ! thanks.
by the way , do you have a plan to upgrade scala3.7.8 kernel for almond.sh?

alexarchambault added a commit that referenced this pull request Jan 22, 2026
)

Follow-up of #1684

This makes `repl.load` accept "raw" sources starting with `package`.
These are assumed to be standard Scala files, and are passed as-is to
scalac.

```scala
@ repl.load("""package thing

  case class Foo(n: Int)
  """)

@ thing.Foo(2)
res1: thing.Foo = Foo(n = 2)
```

Co-authored-by: Lorenzo Gabriele <lorenzolespaul@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants