Skip to content

Commit

Permalink
add inline code macros
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Nov 19, 2024
1 parent d55886c commit 327e5d2
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 157 deletions.
19 changes: 19 additions & 0 deletions site/text/experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ StdDev ← √(^0^1^0)‼(÷⧻⟜/+|×.-).
StdDev [1 2 3 4]
```

An inline code macro can be specified by putting a `^` between the `)` and the first `!`.

```uiua
# Experimental!
(⇌)^‼(⊂1|⊂2) []
```

```uiua
# Experimental!
($"_ ← 5"⊢)^!X
X
```

```uiua
# Experimental!
(repr⋅⊢)^!+
(repr⋅⊢)^!⊓+¯
```

## [derivative](/docs/derivative) and [integral](/docs/integral)

These modifiers transform a mathematical expression.
Expand Down
6 changes: 4 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ pub struct Comments {
pub struct InlineMacro {
/// The function
pub func: Sp<Func>,
/// The span of a `^` that makes this an array macro
pub caret_span: Option<CodeSpan>,
/// The identifier, which consists of only exclamation marks
pub ident: Sp<Ident>,
}
Expand Down Expand Up @@ -414,7 +416,7 @@ impl fmt::Debug for Word {
Word::SemanticComment(comment) => write!(f, "{comment}"),
Word::OutputComment { i, n, .. } => write!(f, "output_comment({i}/{n})"),
Word::Subscript(sub) => sub.fmt(f),
Word::InlineMacro(InlineMacro { ident, func }) => {
Word::InlineMacro(InlineMacro { ident, func, .. }) => {
write!(f, "func_macro({:?}{}))", func.value, ident.value)
}
}
Expand Down Expand Up @@ -589,7 +591,7 @@ impl fmt::Debug for Modifier {
match self {
Modifier::Primitive(prim) => prim.fmt(f),
Modifier::Ref(refer) => write!(f, "ref({refer:?})"),
Modifier::Macro(mac) => write!(f, "macro({:?})", mac.func),
Modifier::Macro(mac) => write!(f, "macro({:?}{})", mac.func, mac.ident),
}
}
}
Expand Down
Loading

0 comments on commit 327e5d2

Please sign in to comment.