what is a "functional" language?

u0206397

Senior Member
Joined
Jul 15, 2009
Messages
764
Reaction score
0
As above. Any simple explanation?

Many languages have functions, procedures, routines or methods too.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,497
Reaction score
1,255
As above. Any simple explanation?

Many languages have functions, procedures, routines or methods too.

functional programming language are like Lisp, Erlang, Haskell, Scheme, Ocaml. follows in a free side effect manner, they are based on a mathematical programming concept from Lambda Calculus.

When I meant side effect,
"a = 1" return value is 1, the operation of "a" begin assigned with 1 is a side effect.

Functional languages emphasis on the idea of input(s) provided to a function to produce an output. Which is why you will notice a lot of functional languages have the behaviour of wrapping on function into another f(g(h()))

This functional behaviour do exhibit in different forms, like in Lisp, they exist as

(OPERATOR OPERAND OPERAND .... OPERAND)
such as
(CAR (CDR <LIST>))

You will want to first study on Lambda Calculus to get a feel of how functional programming concept works.

For proper programming languages terminology,

PROCEDURE is a list of imperative steps to programming. These steps transit via side effects, not necessarily in a functional manner.

METHOD is an action onto the INSTANCE/OBJECT. This relationship is part of OOPL.

FUNCTION found in any programming languages can be functional, but it can be not in this manner too. Imperative programming languages normally just describe it as a set of statements that eventually return a value.

FUNCTIONAL in functional languages, the focus on side effect free, which is useful to immutability.

Take simple arithmetic operations like 1 + 2 * 3 - 4

The functional approach will be to visualise it in postfix functional form as such

(- (+ 1 (* 2 3)) 4)

Functional programming languages also have one very distinctive feature, known as lazy evaluation. On the other hand, Imperative programming languages are mostly eager evaluation.

In C for eg:

F(H())

H() is always eagerly evaluated before placed as input for F,

For functional languages, F is evaluated using H() as input, but H() will only be evaluated(or in lambda calculus term "reduce"), only when applied on runtime inside F. Effectively there could be a divide by zero error existing in H() that is never evaluated if it is never applied inside F. This is a form of closure feature found in programming languages
 
Last edited:

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,673
Reaction score
519
:s13: Good morning davidktw,
:o Learned LISP a long time ago. Here goes... CAR is car. CDR is coulder. :D

I remembered some mischievous student typed in this.... (SHYT..... ). The system responded with .... HOLD OUT YOUR HARDS. :eek: It was trying to give him some SHYT. :D

Damn censor.... just replace Y with I. :o
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,497
Reaction score
1,255
:s13: Good morning davidktw,
:o Learned LISP a long time ago. Here goes... CAR is car. CDR is coulder. :D

I remembered some mischievous student typed in this.... (SHYT..... ). The system responded with .... HOLD OUT YOUR HARDS. :eek: It was trying to give him some SHYT. :D

Damn censor.... just replace Y with I. :o

Good morning too. cold morning to start the day.
 

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,673
Reaction score
519
Good morning too. cold morning to start the day.

This is not cold at all. Can you imagine waking up at 6:30am and going out at 7am and walk 5km to engineering college in -5 degree C ? It's a matter of getting use to it. Summer heat is a lot harder to take. :o
 

u0206397

Senior Member
Joined
Jul 15, 2009
Messages
764
Reaction score
0
Thank you davidktw. Finally found an explanation that is more digestible.

Those explanations by the ang moh elsewhere too chim already.
 

ExtremeWays

Banned
Joined
Mar 17, 2017
Messages
7,399
Reaction score
1
:s13: Good morning davidktw,
:o Learned LISP a long time ago. Here goes... CAR is car. CDR is coulder. :D

I remembered some mischievous student typed in this.... (SHYT..... ). The system responded with .... HOLD OUT YOUR HARDS. :eek: It was trying to give him some SHYT. :D

Damn censor.... just replace Y with I. :o

Still have caddr cadddddr......

I like such clean looking function
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,497
Reaction score
1,255
how about javascript? is javascript a functional language?

Javascript is not a functional language. It started off as a prototype object based language. I recall in the very early stage, you don't even get to create your own object. You can only use those which are defined in the context of a web document such as Window, Location and so forth

https://www.w3.org/community/webed/wiki/A_Short_History_of_JavaScript

But these days, the evolution of programming languages introduce functional features into them
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ. Forum members and moderators are responsible for their own posts.

Please refer to our Community Guidelines and Standards, Terms of Service and Member T&Cs for more information.
Top