[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

is this considered functional?

Remco Hh

6/9/2009 7:39:00 PM

I am reading stuff about functional programming in ruby.

what i do more lately is this:

var = <condition> ? "val1" : "val2:

instead of:
<condition> ? var="val1" : var="val2"

is the first line also an example of functional programming?
--
Posted via http://www.ruby-....

3 Answers

pjb

6/9/2009 8:26:00 PM

0

Remco Hh <remco@huijdts.nl> writes:

> I am reading stuff about functional programming in ruby.
>
> what i do more lately is this:
>
> var = <condition> ? "val1" : "val2:
>
> instead of:
> <condition> ? var="val1" : var="val2"
>
> is the first line also an example of functional programming?

This might be considered a syntactic detail.

Functional programming is characterized by the use of mathematic
functions as a model of computation, which avoids state and mutable
data.

There's no notion of mutation in the usual mathematical objects (it's
possible to modelize state and mutation mathematically, but it
involves more complex structures).

So, if you assign only once each variable var, it can be considered as
a binding, that is like a mathematical "variable".

When we say mathematically "let y0 be f(0)", the variable y0 doesn't
change (it's a constant really).


Notice that avoiding state is rather antinomic to Object Oriented
Programming, since objects are defined by the encapsulation of both
state and program. If you remove state, there remains only program,
that is functions.

Well, you may keep objects, but without mutation, that is you may bind
values to an object instance variable only at initialization time, and
once the object is created, it mustn't change.


http://groups.google.com/group/comp.lang.ruby/search?group=comp.lang.ruby&q=functional+group%3Acomp.lang.ruby+&qt_g=Search+...

--
__Pascal Bourguignon__

MovingBeyondtheRecordButton

3/26/2010 2:48:00 PM

0

By name I as referring to Num in the post above.

"MovingBeyondtheRecordButton" wrote:

> I decide to use:
>
> For Each F In Worksheets("Sheet1").Range("A4:A40,F4:F40")
> If F.Value <> "" Then
> Num = 1000 & F.Value
> 'Then take Num and run Sql Query
>
>
> "Don Guillett" wrote:
>
> > I have no idea what you mean by "give a name". You would NOT want to name
> > each cell.
> >
> > Sub addto()
> > dim f as range
> > For Each f In Worksheets("Sheet30").Range("A4:A40", "F4:F40")
> > If Len(Application.Trim(f)) > 0 And IsNumeric(f) Then
> > f.Value = 1000 & f.Value
> > End If
> > Next f
> > End Sub
> >
> > --
> > Don Guillett
> > Microsoft MVP Excel
> > SalesAid Software
> > dguillett@gmail.com
> > "MovingBeyondtheRecordButton"
> > <MovingBeyondtheRecordButton@discussions.microsoft.com> wrote in message
> > news:A486B6A6-9EAD-4ECA-A640-392FB8119773@microsoft.com...
> > > How do I take the value from each cell defined in the
> > > range("A4:A40,F4:F40")
> > > and place 1000 before the value and give this new number a name.
> > >
> > > Example:
> > > Number in A4 is 37984
> > > I want to use 100037984
> > >
> > > I have tried...
> > >
> > > Dim F As Range
> > > Dim myNum As Variant
> > > Dim Num As Long
> > > Worksheets("Sheet1").Activate
> > > For Each F In Range("A4:A40", "F4:F40")
> > > myNum = F.Value
> > > Num = myNum & 1000
> > >
> > >
> > >
> >
> > .
> >

Don Guillett

3/26/2010 6:54:00 PM

0

However, if you have text or the "dreaded space bar" in the cell then you
will still get 1000 ......

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"MovingBeyondtheRecordButton"
<MovingBeyondtheRecordButton@discussions.microsoft.com> wrote in message
news:05A7D95A-CEC7-406A-89AE-888224BDAF03@microsoft.com...
>I decide to use:
>
> For Each F In Worksheets("Sheet1").Range("A4:A40,F4:F40")
> If F.Value <> "" Then
> Num = 1000 & F.Value
> 'Then take Num and run Sql Query
>
>
> "Don Guillett" wrote:
>
>> I have no idea what you mean by "give a name". You would NOT want to name
>> each cell.
>>
>> Sub addto()
>> dim f as range
>> For Each f In Worksheets("Sheet30").Range("A4:A40", "F4:F40")
>> If Len(Application.Trim(f)) > 0 And IsNumeric(f) Then
>> f.Value = 1000 & f.Value
>> End If
>> Next f
>> End Sub
>>
>> --
>> Don Guillett
>> Microsoft MVP Excel
>> SalesAid Software
>> dguillett@gmail.com
>> "MovingBeyondtheRecordButton"
>> <MovingBeyondtheRecordButton@discussions.microsoft.com> wrote in message
>> news:A486B6A6-9EAD-4ECA-A640-392FB8119773@microsoft.com...
>> > How do I take the value from each cell defined in the
>> > range("A4:A40,F4:F40")
>> > and place 1000 before the value and give this new number a name.
>> >
>> > Example:
>> > Number in A4 is 37984
>> > I want to use 100037984
>> >
>> > I have tried...
>> >
>> > Dim F As Range
>> > Dim myNum As Variant
>> > Dim Num As Long
>> > Worksheets("Sheet1").Activate
>> > For Each F In Range("A4:A40", "F4:F40")
>> > myNum = F.Value
>> > Num = myNum & 1000
>> >
>> >
>> >
>>
>> .
>>