Programming

In my last article, I showed how we can use Prolog to generate univariate Polynomials. After I finished that article, I wanted to try Lisp for the same task. Prolog is “declarative”, whereas Lisp is primarily “functional” (it supports OOP as well), so the implementation will exhibit that difference. Here is the primary function generate-polynomial […]

Polynomial is an important topic in High School maths curriculum. There are many online courses that explain the topic in great details with lots of examples and sample exercises. Wouldn’t it be interesting if we can generate polynomials of given degree programmatically? It turns out that this is not such a hard problem after all. […]

The constinit specifier, introduced in C++20, is applied to static variables (global and local static) and thread local variables, with the requirement that they either have a zero initialization or they are initialized with a compile-time constant expression. Here is our first example: Line 17 declares a global constinit variable, initialized with a constant value. […]

“If consteval” is useful in the context of calling a consteval function from within a constexpr function. A consteval function can only be invoked in a constant expression and hence is evaluated at compile-time. On the other hand, a constexpr function may be invoked in a constant expression or non-constant expression. If invoked in a […]

The zip() function in Python is a convenient mechanism for iterating over multiple “iterables” in parallel. Looping over lists is a common scenario. Here is the output generated by the above code: Common Lisp does not have such a feature built into the language or as part of the standard library. Of course, we have […]

The type trait “std::is_scoped_enum<T>::value” was introduced in C++23 to check whether the type “T” is a scoped enum type. Another way to use this is std::is_scoped_enum_v<T>. Before getting into this trait in detail, let us briefly recap the differences between unscoped and scoped enums. Unscoped Enums Unscoped enums are the old-style enums. Look at the […]

In addition to the conventional “==” operator that checks if two objects are equal, Julia has the “===” operator to check for equality. What is the difference between these two operators? The “==” operator checks whether two objects have the same value. Here are some examples: Cell 5 shows that the RHS float value is […]

The ability to enumerate stack frames at runtime is one of the interesting features introduced in C++23. This is made possible through the <stacktrace> header. The interface is quite simple. Here is a piece of code showing how to use the library. There are 4 functions and here is the call chain: The “dumpStackTrace()” function […]

I had written about std::optional<> in an earlier article. C++23 introduces std::expected<> as an interesting extension to std::optional<>. Whereas std::optional<> contains a value or none at all, std::expected<> contains a value or an error code associated with it. This gives better control to the caller in terms of handling the outcome of the function call. […]
Recent Comments