You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/modules/2-bundle/4-conventions/2-abstractions.md
+10-3Lines changed: 10 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,8 +35,8 @@ Functionally, `Sound` behaves like a primitive type: as far as a cadet using the
35
35
## Breaking Abstractions with `display` and `stringify`
36
36
37
37
`js-slang` provides a built-in function for converting any value into a string: `stringify()`. `display()` behaves like the typical `console.log` and prints the string representation
38
-
as returned by `stringify` to the REPL. Under the hood, `stringify` uses the default Javascript `toString` functionality to convert primitive types to their string representations. This does
39
-
mean that for "primitives" that are actually objects, `js-slang`'s default implementation will end up exposing implementation details.
38
+
as returned by `stringify` to the REPL. Under the hood, `stringify` uses the default Javascript `toString` functionality to convert Javascript types to their string representations. This does
39
+
mean that for Source primitives that are actually Javascript objects, `js-slang`'s default implementation will end up exposing implementation details.
40
40
41
41
Taking an example from the `curve` bundle, `RenderFunction`s are considered a type of primitive. Without any further changes, calling `display` on a `RenderFunction` produces the following
42
42
output:
@@ -116,6 +116,13 @@ export class Point implements ReplResult {
116
116
`Point` is a class that directly implements the `ReplResult` interface. If it didn't implement this interface, then calling `display(make_point(20, 20))`
117
117
would result in the infamous `[object Object]` being printed.
118
118
119
+
The type doesn't have to be a class, it can also be a Typescript [interface](https://www.typescriptlang.org/docs/handbook/2/objects.html):
120
+
```ts
121
+
interfaceThingextendsReplResult {
122
+
// ...implementation details
123
+
}
124
+
```
125
+
119
126
The benefit of implementing the interface this way in Typescript is that it enables type-checking to ensure that the interface is properly implemented.
The idea is that the abstraction of the `TextOptions` type is never broken and that the cadet never interacts with the object directly.
261
+
The idea is that the abstraction of the `TextOptions` type is never broken and that the cadet never interacts with the object's component parts directly.
Copy file name to clipboardExpand all lines: docs/src/modules/2-bundle/4-conventions/3-errors.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ Then, the error can be thrown with the correct function name. Otherwise, cadets
53
53
that is visible to them. Many other functions might rely on `throwIfNotRune`. If they were all called in the same program, it doesn't tell the cadet which function the error was thrown from
54
54
(was it `show`? or `anaglyph`? or something else?)
55
55
56
-
## Type Checking
56
+
## Source Type Checking
57
57
58
58
Though bundles are written in Typescript, Source (except for the Typed Variant) does not support anything beyond rudimentary type checking. This means that it can determine that an expression
59
59
like `1 - "string"` is badly typed, but it can't type check more complex programs like the one below, especially when bundle functions are involved:
Now, the tests foryour tab will be runin browser mode.
231
+
You will also need to add (to your dev dependencies) other packages:
232
+
- `@vitest/browser`
233
+
- `vitest-browser-react`
234
+
- `playwright`
235
+
236
+
In the case of `playwright`, you might also have to run `playwright install chromium`.
237
+
238
+
If your system doesn't have the necessary dependencies for `playwright`'s install, you will have to run `playwright install chromium --with-deps` instead.
239
+
240
+
Now, the tests foryour tab can be runin browser mode.
232
241
233
242
> [!INFO] Default Browser Instance
234
243
> By default, one `chromium` browser instance will be provided. This should be sufficient, but you can always
235
244
> add more instances if necessary.
245
+
>
246
+
> Then, you will also have to specify this instance when running the `playwright` installation command above.
0 commit comments