Skip to main content

Form

Struct Form 

Source
pub struct Form {
    pub kind: FormKind,
    pub span: Span,
}
Expand description

A parsed Clojure form with its source location.

PartialEq ignores spans so test assertions can compare forms without constructing exact span values.

Fields§

§kind: FormKind§span: Span

Implementations§

Source§

impl Form

Source

pub fn new(kind: FormKind, span: Span) -> Self

Source

pub fn heap_size(&self) -> usize

Total heap bytes owned by this form tree (excluding the Form itself).

Source

pub fn is_kwargs_rest_pattern(&self) -> bool

True when this form, used as a variadic & rest pattern, selects Clojure’s keyword-argument convention.

A map-shaped rest pattern ([& {:keys [a b]}]) does not destructure the rest sequence; the trailing arguments are first normalized into a map (Value::from_kwargs_rest) and the pattern is applied to that. Every execution tier has to make this call the same way — the tree-walker in bind_fn_params, and both lowerers on their way to KnownFn::KwargsMap — so they share this predicate rather than three copies of the match. Issue #368 was those copies disagreeing.

Source

pub fn unmeta(&self) -> &Form

The annotated form with every ^meta wrapper removed.

Returns self when the form carries no metadata. Stacked metadata (^:a ^:b x) is peeled down to the innermost form.

Source

pub fn quoted_value_supports_meta(&self) -> bool

True when an evaluated-position ^meta annotation on this form becomes runtime metadata on the value it produces.

Only a form that constructs an IObj qualifies — a collection literal or a function. Every other form (a call, a symbol, quote, if, do) takes the annotation as a compile-time hint and evaluates to an unannotated value, so (meta ^{:a 1} (list 1)) and (meta ^{:a 1} x) are both nil.

Every execution tier consults this one predicate: the tree-walker in interp::eval, and IR lowering in lower::anf for the JIT and AOT paths. A tier that disagreed would make meta depend on how hot the code got.

True when the value this form denotes as data can carry metadata.

Inside quote every form is a literal, so whether an annotation lands is a question about the form and needs no runtime test: '^{:a 1} [1] carries it, '^{:a 1} 42 cannot. Mirrors supports_meta in cljrs-runtime over the values form_to_value produces — a reader macro ('x, @x, #'x, `x) denotes a list, and #(…) denotes the fn* list it expands to.

Source

pub fn takes_runtime_meta(&self) -> bool

Inside quote the rule does not apply: there the annotation is data and lands on any value that can carry it.

Source

pub fn peel_meta(&self) -> (Vec<&Form>, &Form)

The ^meta forms attached to this form, outermost first, together with the annotated form itself.

Source

pub fn as_symbol(&self) -> Option<&str>

The symbol name, if this form is a symbol.

Source

pub fn as_keyword(&self) -> Option<&str>

The keyword name (without the leading :), if this form is a keyword.

Source

pub fn as_string(&self) -> Option<&str>

The string contents, if this form is a string literal.

Source

pub fn as_list(&self) -> Option<&[Form]>

The elements, if this form is a list.

Source

pub fn as_vector(&self) -> Option<&[Form]>

The elements, if this form is a vector.

Source

pub fn as_map(&self) -> Option<&[Form]>

The flat key/value pairs, if this form is a map literal.

Trait Implementations§

Source§

impl Clone for Form

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Form

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Form

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl Freeze for Form

§

impl RefUnwindSafe for Form

§

impl Send for Form

§

impl Sync for Form

§

impl Unpin for Form

§

impl UnsafeUnpin for Form

§

impl UnwindSafe for Form

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.