#User-defined global variable in template, for function

7 messages · Page 1 of 1 (latest)

true dragon
#

I'm attempting to make a dictionary template aimed at conlangs. part of this involves a user-defined variable, clong-dict-types, which defines all word types/parts of speech and their formatting. The problem is, im having problems setting it up in a way that the template-defined entry() function recognizes the user-defined value.

clong-dict-types and entry() outside and before .with(): entry() only recognizes the default value of (:), not the user-defined value.
clong-dict-types in .with(), entry() outside + before .with(): entry() doesnt recognize the existence of clong-dict-types()
same as above but clong-dict-types initialized as (:) before entry() definition: only recognizes default value
both inside .with(): main.typ() doesnt recognize existence of entry()

probably other configurations ive tried, but i cant get anything to work

#

current setup (irrelevant code excluded):
main.typ

#import "@local/clong-dict:0.1.0": * 
[...] // configurations

#let _clong-dict-types = (
  noun: (
    sym: "N",
    infl: [decl.],
    forms: (
      pl: ([_pl._], true),
      pat: ([_pat._], false),
      voc: ([_voc._], false),
      dat: ([_dat._], false),
    ),
    cats: ("gender", "anim")
  ),
)

#show: clong-dict.with(
  title: [Classical Bandi Dictionary],
  series: [The Panidan Languages],
  author: [Submerg],
  issue: [\#3D],

  types: (
    noun: (
      sym: "N",
      infl: [decl.],
      forms: (
        pl: ([_pl._], true),
        pat: ([_pat._], false),
        voc: ([_voc._], false),
        dat: ([_dat._], false),
      ),
      cats: ("gender", "anim")
    ),
  ),
  [...] // appendix
)

[...] // section stuff

= V
#entry(("noun"), "vácai", [Leaf.],
  forms: (decl: 1,
          pl: "vacáin",
          pat: "vacaivái",
          voc: "vacáite",
          dat: "vacazái",
          other: ((smallcaps[pl.voc], "vacaḯten"),)
          ),
  cats: (gender: [m], anim: [an])
)

[...] // more section stuff

local/clong-dict/0.1.0/lib.typ

#import "@preview/nth:1.0.1": nths

#let _clong-dict-types = (:)

#let entry(
  type,
  word,
  def,
  forms: (:),
  cats: (:),
) = {
  assert(type in _clong-dict-types, message: "Unknown word type '" + type + "'." + repr(_clong-dict-types))
  let tdef = _clon-dict-types.at(type) // definition of the word's type
  word
  [ ]

  if type(tdef) == str [*#tdef*]
  else {
    [(]
    if tdef.infl != none {

    }
  }

  [ $bullet$ #def]
}

#let clong-dict(
  title: none,
  series: none,
  author: none,
  issue: none,
  types: (:),
  appendix: none,
  doc
) = {
  [...] // miscellaneous configurations
  let _clong-dict-types = types

  page[...] // title page

  [...] // more configurations

  doc

  [...]
}
#

N.B. entry() is undergoing a rewrite since i realized i wrote it as specific to my current conlang

#

current error message:

error: assertion failed: Unknown word type 'noun'.(:)
true dragon
#

boosting this

errant burrow
# true dragon boosting this

They are different variables (each file is its own scope). To do this, you will have to either pass it as an argument to your function, or use state().