# Dynamic Refinements and Function Application

DevFeed: [Dynamic Refinements and Function Application](<https://devfeed.tech/articles/dynamic-refinements-and-function-application-22383.md>)

Original publisher: [Read original article](<https://www.red-lang.org/2023/06/dynamic-refinements-and-function.html>)

Author: Nenad Rakocevic (noreply@blogger.com)

Published: 2023-06-07T22:55:00Z

Content type: article

Language: en

Sources: [Red](<https://devfeed.tech/sources/red.md>)

Topics: [Red](<https://devfeed.tech/topics/red.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [apply](<https://devfeed.tech/tags/apply.md>), [build](<https://devfeed.tech/tags/build.md>), [code](<https://devfeed.tech/tags/code.md>), [examples](<https://devfeed.tech/tags/examples.md>), [functional](<https://devfeed.tech/tags/functional.md>), [hof](<https://devfeed.tech/tags/hof.md>), [technical](<https://devfeed.tech/tags/technical.md>)

## AI overview

This article explains Red's new apply functionality and dynamic refinements. It describes how dynamic refinement values are retrieved from context, how unused arguments are handled, and how Apply/all supplies function parameters in specification order with type-checked logic values for refinement slots.

## Source excerpt

It's Time to Apply Yourself to Red Red has never had an apply function, though we knew it would come someday. In the meantime, some of us rolled our own. Gregg's was simple, neither flexible nor efficient, and just a couple lines of code. Boris made a much more capable version, but it could still only be so fast as a mezzanine. R2 had a mezz version, which suffered the same problem. All that changes now. Apply is dead! Long live Apply! It required deep work, and a lot of design effort, but we think you'll like the results, whether you're a high-level Reducer, or anxious to see how much leverage you can, um, apply, from a functional perspective. Everybody wins. If you don't know what apply is, in terms of functional languages, take a moment and read up. If you can get through the introduction there without getting dizzy, great. If your head is spinning, feel free to stop after the first section of this article and ignore the deep dive. You still get 90% of the value for most high level use cases. Gregg got so dizzy that he fell down, but was still able to help with this article. Function application is largely about composition. How you can combine functions in a concise way for maximum leverage and minimum code. The problem with its design in many languages is that it makes things harder to understand. Rather than concrete functions names, there is indirection and abstraction. It can be tricky to get right, especially in a flexible language like Red, while also maintaining as much safety as possible. You can drive fast, but still wear your seat belt. Dynamic Refinements This subtle feature is likely to see wide use, because it will reduce code and let people build more flexible functions. It's also easy to explain. Here's an example. First, how you would write it today: repend: func [ {Appends a reduced value to a series and returns the series head} series [series!] value /only "Appends a block value as a block" ][ either only [ append/only series reduce :value ][ a