Y-Combinator | Playing around with different Y Combinator | Functional Programming library

 by   calincru C++ Version: Current License: No License

kandi X-RAY | Y-Combinator Summary

kandi X-RAY | Y-Combinator Summary

Y-Combinator is a C++ library typically used in Programming Style, Functional Programming applications. Y-Combinator has no bugs, it has no vulnerabilities and it has low support. You can download it from GitHub.

Let's start with writing a simple recursive factorial function:.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              Y-Combinator has a low active ecosystem.
              It has 5 star(s) with 0 fork(s). There are 1 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              Y-Combinator has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of Y-Combinator is current.

            kandi-Quality Quality

              Y-Combinator has no bugs reported.

            kandi-Security Security

              Y-Combinator has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              Y-Combinator does not have a standard license declared.
              Check the repository for any license declaration and review the terms closely.
              OutlinedDot
              Without a license, all rights are reserved, and you cannot use the library in your applications.

            kandi-Reuse Reuse

              Y-Combinator releases are not available. You will need to build from source code and install.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Y-Combinator
            Get all kandi verified functions for this library.

            Y-Combinator Key Features

            No Key Features are available at this moment for Y-Combinator.

            Y-Combinator Examples and Code Snippets

            No Code Snippets are available at this moment for Y-Combinator.

            Community Discussions

            QUESTION

            Self-reference in function definition
            Asked 2021-Jun-08 at 10:31

            In this explanation of Y-combinator (https://mvanier.livejournal.com/2897.html),

            ...

            ANSWER

            Answered 2021-Jun-07 at 05:53

            Consider the expression (define p M), where M is some expression and p is a variable.

            Let's suppose we're evaluating this expression in environment E. Evaluating (define p M) should do two things:

            1. It should evaluate M in environment E; let the result be x.
            2. It should modify environment E so that p is bound to x.

            So what should happen when we evaluate (define factorialA (almost-factorial factorialA)) in an environment E where factorialA is not already defined?

            First, we try to evaluate (almost-factorial factorialA) in environment E. To do this, we first evaluate almost-factorial, which succeeds. We then evaluate factorialA, which fails because factorialA is not defined in environment E. Thus, the whole thing should be expected to fail.

            On the other hand, if we try

            Source https://stackoverflow.com/questions/67862564

            QUESTION

            Why is it not possible to implement fixed-point combinator like in the definition?
            Asked 2021-May-05 at 20:04

            I'm trying to implement the Y-combinator like in the definition by Curry.

            This code does not work. It causes infinite recursion.

            ...

            ANSWER

            Answered 2021-May-05 at 16:42

            The first string prints out the following error:

            Source https://stackoverflow.com/questions/67404522

            QUESTION

            Y combinator in scheme blows up using Church numbers, but works on regular numbers
            Asked 2021-Apr-23 at 09:54

            I've just read "A Tutorial Introduction to the Lambda Calculus1" by Raul Rojas. I put the lambda expressions into Scheme (TinyScheme) to try them out. Everything worked except the recursive function to calculate the sum of the Church numbers 0,1,...,N using the Y-combinator which runs out of memory. Bizarrely, the Y-combinator works if I calculate the sum using regular numbers.

            Here is my Y-combinator,

            ...

            ANSWER

            Answered 2021-Apr-23 at 09:54

            The lambda calculus only works with normal order reduction (i.e. arguments are only evaluated when their values are needed), and Scheme uses applicative order reduction (arguments are evaluated first), except in "special forms".

            Your code works with regular numbers not because of the numbers, but because of cond, which will evaluate at most one of its clauses.

            If you replace the cond in your sum1 with a regular function, your computation will not terminate with regular numbers either.

            Source https://stackoverflow.com/questions/67212417

            QUESTION

            How do I manage declarations that require template parameters derived from recursive functors/lambdas?
            Asked 2021-Feb-05 at 19:03

            I am attempting to build a clean and neat implementation of recursive-capable lambda self-scoping (which is basically a Y-combinator although I think technically not quite). It's a journey that's taken me to, among many others, this thread and this thread and this thread.

            I've boiled down one of my issues as cleanly as I can: how do I pass around templated functors which take lambdas as their template parameters?

            ...

            ANSWER

            Answered 2021-Feb-05 at 18:54

            The only way I see is make evaluate() a template method; if you want to be sure to receive a Functor (but you can simply accept a callable: see Yakk's answer):

            Source https://stackoverflow.com/questions/66067390

            QUESTION

            Why does Visual Studio compile this function correctly without optimisation, but incorrectly with optimisation?
            Asked 2021-Feb-05 at 16:43

            I'm doing some experimenting with y-combinator-like lambda wrapping (although they're not actually strictly-speaking y-combinators, I know), and I've encountered a very odd problem. My code operates exactly as I'd anticipate in a Debug configuration (with Optimizations turned off), but skips large (and important!) bits in Release (with it set to Optimizations (Favor Speed) (/Ox)).

            Please note, the insides of the lambda functions are basically irrelevant, they're just to be sure that it can recursion correctly etc.

            ...

            ANSWER

            Answered 2021-Feb-04 at 18:14

            Undefined behavior is a non-localized phenomenon. If your program encounters UB, that means the program's behavior in its entirety is undefined, not merely that little part of it that did the bad thing.

            As such, it is possible for UB to "time travel", affecting code that theoretically should have executed correctly before doing UB. That is, there is no "correctly" in a program that exhibits UB; either the program is correct, or it is incorrect.

            How far that goes depends on the implementation, but as far as the standard is concerned, VS's behavior is consistent with the standard.

            Source https://stackoverflow.com/questions/66051169

            QUESTION

            Generating powerset in one function, no explicit recursion, and using only simplest primitives in Racket
            Asked 2020-Dec-03 at 18:37

            Note: this is a bonus for homework, but I have spent way too long on trying things to no avail. Help is much appreciated, but not necessary I suppose.

            Premise: generate a powerset for a list of numbers, but without using any helpers, explicit recursion, looping, or functions/constants other than cons, first, rest, empty?, empty, else, lambda, and cond, while using only one define on the language level Intermediate Student with Lambda. The order of the powerset does not matter.

            What I've tried so far: I have discovered the Y-combinator and anonymous recursion thanks to this post (author has the same end goal but we have different approaches, so the information in his post does not solve my problem), and the powerset code in this answer, and with that I have written the following:

            ...

            ANSWER

            Answered 2020-Nov-19 at 03:44

            the Y-combinator only works with one parameter and combine needs 2

            Any multi-argument function can be imagined as a one-argument function, returning a lambda that waits for the next argument. This process is called currying. For example, if we have

            Source https://stackoverflow.com/questions/64904835

            QUESTION

            Y combinator in elisp
            Asked 2020-May-12 at 19:48

            We can define a recursive function, factorial as an example, by YCombinator as follows

            ...

            ANSWER

            Answered 2020-May-12 at 19:48

            You say you understand this definition:

            Source https://stackoverflow.com/questions/61751659

            QUESTION

            How Recursive types with no leaf cases can be accepted in OCaml?
            Asked 2020-May-03 at 14:13

            It is a well-known fact that OCaml rejects to define bare recursive types such as type t = t -> int and the Y-combinator example in Rosetta Code are not working as well.

            However, recently I found that the little tweak of the recursive type definition like type t = A of (t -> int) works well. The following code is some proof-of-concept works to check which one works well.

            ...

            ANSWER

            Answered 2020-May-03 at 14:13

            Early versions of OCaml happily accepted types such as type t = t -> int. They even inferred them. The problem with that was that in most of the practical cases, such a type just masks a programming error. So by popular demand, they were disallowed, and you now need to need an explicit datatype. You can still get the old behaviour if you use the -rectypes option with the compiler.

            That was merely a pragmatic decision. There is no semantic problem with such types, at least not in a language like OCaml.

            Data types do not need to have non-recursive constructors as "leaf" cases, as long as the type of at least one constructor includes values that do not require another value of the defined type.

            For example,

            Source https://stackoverflow.com/questions/61568932

            QUESTION

            Implement a self-reference/pointer in a pure/functional language (Elm/Haskell)
            Asked 2020-Mar-09 at 19:05
            Abstract Problem:

            I'd like to implement a self-reference / pointer in Elm.

            Specific Problem:

            I'm writing a toy LISP interpreter in Elm inspired by mal.

            I'm attempting to implement something like letrec to support recursive and mutually-recursive bindings (the "self reference" and "pointers" I'm mentioning above).

            Here's some example code:

            ...

            ANSWER

            Answered 2020-Feb-29 at 06:02

            A binding construct in which the expressions can see the bindings doesn't require any exotic self-reference mechanisms.

            How it works is that an environment is created for the variables, and then the values are assigned to them. The initializing expressions are evaluated in the environment in which those variables are already visible. Thus if those expressions happen to be lambda expressions, then they capture that environment, and that's how the functions can refer to each other. An interpreter does this by extending the environment with the new variables, and then using the extended environment for evaluating the assignments. Similarly, a compiler extends the compile-time lexical environment, and then compiles the assignments under that environment, so the running code will store values into the correct frame locations. If you have working lexical closures, the correct behavior of functions being able to mutually recurse just pops out.

            Note that if the assignments are performed in left to right order, and one of the lambdas happens to be dispatched during initialization, and then happens to make a forward call to one of lambdas through a not-yet-assigned variable, that will be a problem; e.g.

            Source https://stackoverflow.com/questions/60460322

            QUESTION

            Y-combinator does not seem to have any effect
            Asked 2019-Jul-07 at 00:00

            I tried using the y-combinator (in both Lua and Clojure) as I thought that would allow me to exceed the size of default stack implementations when using recursion. It seems I was mistaken. Yes, it works, but in both of these systems, the stack blows at exactly the same point as it does using plain old recursion. A lowish ~3600 in Clojure and a highish ~333000 on my Android Lua implementation. It is also a bit slower than regular recursion.

            So is there anything to be gained by using the y-combinator, or is it just an intellectual exercise to prove a point? Have I missed something?

            ===

            PS. Sorry, I should have made it clearer that I am aware I can use TCO to exceed the stack. My question does not relate to that. I am interested in this a) from the academic/intellectual point of view b) whether there is anything that can be done about those function that cannot be written tail recursively.

            ...

            ANSWER

            Answered 2018-Jun-20 at 02:57

            A “tail call” will allow you to exceed any stack size limitations. See Programming in Lua, section 6.3: Proper Tail Calls:

            ...after the tail call, the program does not need to keep any information about the calling function in the stack. Some language implementations, such as the Lua interpreter, take advantage of this fact and actually do not use any extra stack space when doing a tail call. We say that those implementations support proper tail calls.

            Source https://stackoverflow.com/questions/50939363

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install Y-Combinator

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/calincru/Y-Combinator.git

          • CLI

            gh repo clone calincru/Y-Combinator

          • sshUrl

            git@github.com:calincru/Y-Combinator.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Functional Programming Libraries

            ramda

            by ramda

            mostly-adequate-guide

            by MostlyAdequate

            scala

            by scala

            guides

            by thoughtbot

            fantasy-land

            by fantasyland

            Try Top Libraries by calincru

            KISS

            by calincruHTML

            Dotfiles

            by calincruPython

            15-Puzzle

            by calincruC++

            UltimateTicTacToe

            by calincruC++