134 questions
0
votes
0
answers
45
views
From Abstract Syntax Tree to machine code. Functions as first-class objects compilation?
I have created a front-end for my language. I have also been able to transpile to C so that it can be compiled. In this language, functions are treated as first-class objects.
Is it possible to ...
2
votes
2
answers
71
views
Function returned from another function
I observed a difference in output when trying to run similar function.
function func1(){
function sum(){
console.log(2+5);
}
return sum();
}
func1();
function func2(){
...
-1
votes
2
answers
2k
views
Are first order function and first class functions same in JavaScript? [duplicate]
What are first class functions and first order functions? Are both are same or not? Are there any similarities/difference between first order and first class functions in JavaScript?
I tried to get an ...
0
votes
1
answer
29
views
On the fly function expression doesn't throw error when triggering with first class [duplicate]
I am learning Javascript and I came across these concepts of function expressions & first class functions.
While I do understand their definition, I am unable to understand why my code behaves the ...
5
votes
2
answers
195
views
Can function templates be used as first class citizens in higher order function calls?
Passing a function template as argument to another function template is always a bit tricky. Typically one has to resort to creating a lambda object that goes and calls the original function.
Example
...
0
votes
2
answers
53
views
How to write a JavaScript function that works both as a first-class function and higher-order function? [duplicate]
For example let's take the function add. I want to be able to call:
add(1, 2)(3, 4)
and
add(1, 2)
using same implementation.
I have tried writing the add function the following way:
var add = (a, b) ...
1
vote
1
answer
132
views
Representing a queue as a procedure with local state
Section §2.1.3 at page 90 explains, with a very clear example, that first class functions in a language make functions themselves and data be the same thing looked at from different perspectives, or, ...
0
votes
1
answer
142
views
type mismatch when create a kotlin infix notation to nest a function to another
I am trying to create a infix notation as a extension function of (Int) -> Int function which is used to nest a function to another.
For example:
class Entry {
companion object {
...
4
votes
3
answers
440
views
How many of these points in the definition of a first-class element do Java's functions satisfy?
Structure and Interpretation of Computer Programs gives the following as the conditions that an element of a programming language must satisfy to be considered first-class:
They may be named by ...
1
vote
1
answer
2k
views
How to call a function stored as variable with arguments - Python 3
def some_function():
print("This will always be the same")
def some_other_function(text):
print(text)
some_variable = "hello"
list_of_elements = [
"element_one&...
-1
votes
2
answers
601
views
Why i only need to provide "console.log" to my catch promise method to log error?
I have a simple promise, but I wonder why in my catch method I only need to pass "console.log" and it will automatically log that error if it happens?
Does it have something to do with the ...
0
votes
3
answers
51
views
Difficulty Iterating Through Function Call - First Class Functions
The code I have provided executes properly, however as you will see it offers refreshments to each guest repeatedly before moving on to the next guest.
I'm scratching my head as to how I can alter my ...
0
votes
1
answer
61
views
python: assigning first class function to dictionary item
I have an existing dictionary and I want to add new element as a first-class function generated from a list.
Is there a more pythonic way of doing this?
agg_dict = {}
for x in attribute_list:
...
1
vote
2
answers
2k
views
Is there any difference between First Class Functions and Callback Functions in Javascript?
Are there any differences between first class functions and callback functions in javascript? I thought that first class functions were functions that were treated as regular variables and can be ...
0
votes
0
answers
130
views
Why is a list of anonymous closures not identical to a list of evaluations of anonymous enclosing functions? [duplicate]
Note: This concept is touched upon in Lambda function in list comprehensions, but not to a sufficient depth for my understanding.
We start with an example (in Python) of a closure:
def ...
0
votes
3
answers
313
views
Executing higher-order functions
I'm learning the concepts of first class functions and closures in Python and I was curious to know:
Given a higher-order function:
def html_tag(tag):
def wrap_text(text):
print("<{0}&...
1
vote
1
answer
142
views
Swift: Calling an Enum value converter function as a first class function
enum SolarSystemPlanet: String, CaseIterable {
case mercury, venus, earth, mars, jupiter, saturn, uranus, neptune
func toRawValue(_ value: SolarSystemPlanet) -> PlanetName {
value....
0
votes
4
answers
1k
views
How to implement currying in javascript?
Question as below:
create a sum function, and the requirement:
sum(1,2).result === 3
sum(1,2)(3).result == 6
sum(1,2)(3,4).result == 10
sum(1,2)(3,4)(5).result == 15
This is a question about ...
0
votes
1
answer
249
views
Type mismatch on basic "apply twice" hello world in Haskell
The minimal code:
twice :: (a -> a) -> a -> a
twice f = f . f
main = do
return twice ++ "H"
The errors generated:
stack runhaskell "c:\Users\FruitfulApproach\Desktop\Haskell\test.hs"
C:...
0
votes
4
answers
81
views
JS :: First Class Functions :: Parameter Value Confusion
I do not understand how the parameter of the first class function, "number", has the value it does.
I have been mulling over this problem for a couple of days and I am not making any progress in my ...
0
votes
1
answer
108
views
How these two functions are equivalent?
I am reading a book Mostly adequate guide and in the chapter about First Class functions, I have come across this example. Can somebody explain it to me?
It says the below two lines are equal.
// ...
5
votes
2
answers
862
views
Are Kotlin functions really first class types?
Does the fact that this doesn't compile mean that they're not quite first class types?
fun foo(s: String): Int = s.length
// This won't compile.
val bar = foo
Is there a way to do this without ...
0
votes
0
answers
58
views
Replacing Element in a Set if a condition is met
I'm working with a Set of CarCagetory:
public struct Images {
static let categoryTeaser = UIImage()
}
public enum PremiumModel {
case model1, model2, model3, unknown
}
public struct ...
1
vote
1
answer
712
views
Initializing a class variable with array of class functions
I would like to create an array of member functions as a class variable so I can switch throughout the class etc. The following doesn't work
class A:
def b(self):
pass
def c(self):
...
1
vote
0
answers
67
views
Is it possible to get a first class function with default parameters?
I have a bunch of similar functions, which all have the same parameters. Some of the parameters have a default value.
Here are two of them:
func debug(_ message: String, eventid: String = Foundation....