Search code examples
cguile

How does one perform conditional statments on SMOB types?


I know that Guile has a scm_assert_smob_type function, but I do not believe that it returns a boolean.

I want to be able to do something like:

if (type(smob) == int_smob)
{
    int_foo(smob);
}

else if (type(smob) == string_smob)
{
    string_foo(smob);
}

Solution

  • You can check scm_assert_smob_type's definition for hints:

    void
    scm_assert_smob_type (scm_t_bits tag, SCM val)
    {
      if (!SCM_SMOB_PREDICATE (tag, val))
        scm_wrong_type_arg_msg (NULL, 0, val, scm_smobs[SCM_TC2SMOBNUM(tag)].name);
    }
    

    As you can see, it utilizes SCM_SMOB_PREDICATE which does return a boolean. The macro is for public use and is defined in <smob.h>.