|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>> you suddenly realise that you'd like to use the number on the top of
>> the stack as the *denominator*, not the numerator, or something like
>> that.
>
> I think there's a button for *that* case, actually.
Division and subtraction are the obvious ones. (Oh, and exponent if
there's a button for that.)
Thinking about it, a button to swap the top two operands ought to fix
most problems you might have.
I also anticipate that being able to somehow "inspect" the stack might
come in handy if you can't remember what you put on there already...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v8 wrote:
> Thinking about it, a button to swap the top two operands ought to fix
> most problems you might have.
That's kind of what I was referring to, yes.
> I also anticipate that being able to somehow "inspect" the stack might
> come in handy if you can't remember what you put on there already...
Yes. I expect such a thing might have been around on some of the
calculators I remember seeing.
--
Darren New / San Diego, CA, USA (PST)
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On Fri, 15 Aug 2008 08:58:35 +0100, Invisible wrote:
> Nicolas Alvarez wrote:
>
>> JavaScript functions don't need names.
>>
>> var value = (function (x) {
>> return 3*x + 5;
>> })(42);
>>
>> That actually works.
>
> Ooo... that's interesting.
Python:
value = (lambda(x): 3*x+5)(42)
Lua:
value = (function(x) return 3*x+5 end)(42)
Ruby (1):
def test
yield 42
end
value = test { |x| 3*x+5 }
Ruby (2):
value = lambda { |x| 3*x+5 } .call(42)
C++0x:
int main()
{
int value = <>(int x) (3*x+5) (42);
}
(I would have tested this, but the build instructions
at http://parasol.tamu.edu/groups/pttlgroup/lambda/
don't work for me, tried to computers...)
i386 assembly (ok, this is cheating):
mov eax, 42
call over
lea eax, [eax*2+eax+5]
ret
over:
pop eax
call eax
mov [value], eax
--
Joel Yliluoma - http://iki.fi/bisqwit/
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Joel Yliluoma wrote:
> Python:
>
> value = (lambda(x): 3*x+5)(42)
>
> Lua:
>
> value = (function(x) return 3*x+5 end)(42)
>
> Ruby (1):
>
> def test
> yield 42
> end
> value = test { |x| 3*x+5 }
>
> Ruby (2):
>
> value = lambda { |x| 3*x+5 } .call(42)
>
> C++0x:
>
> int main()
> {
> int value = <>(int x) (3*x+5) (42);
> }
>
> i386 assembly (ok, this is cheating):
> mov eax, 42
> call over
> lea eax, [eax*2+eax+5]
> ret
> over:
> pop eax
> call eax
> mov [value], eax
Haskell [is that cheating??]
value = (\x -> 3*x + 5) 42
Lambda calculus:
\i ->
(\n -> \m -> \f -> \x -> n f (m f x))
(
(\n -> \m -> \f -> \x -> n (m f) x)
(\f -> \x -> f (f (f x)))
i
)
(\f -> \x -> f (f (f (f (f x)))))
[I can't be bothered to write "42" in the lambda calculus. Suffice it to
say it contains 42 copies of the letter "f".]
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Joel Yliluoma wrote:
> C++0x:
>
> int main()
> {
> int value = <>(int x) (3*x+5) (42);
> }
I thought it was [], not <>.
But I don't have any C++0x compiler...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Nicolas Alvarez <nic### [at] gmailcom> wrote:
> Joel Yliluoma wrote:
> > C++0x:
> >
> > int main()
> > {
> > int value = <>(int x) (3*x+5) (42);
> > }
> I thought it was [], not <>.
I suppose the exact syntax has still not been written to stone. The
current wikipedia article on the subject uses your syntax:
http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> I suppose the exact syntax has still not been written to stone. The
> current wikipedia article on the subject uses your syntax:
>
> http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions
>
It's not a feature I'm likely to use much, anyway. I'm more interested in
the range-based for loop (yes, I know it's pure syntax sugar), and template
concepts.
Currently:
for (std::vector<int>::iterator i = myList.begin(); i != myList.end(); ++i)
With the new type determination feature:
for (auto i = myList.begin(); i != myList.end(); ++i)
With the range-based for loop:
for (int &x : myList)
<3
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Nicolas Alvarez <nic### [at] gmailcom> wrote:
> It's not a feature I'm likely to use much, anyway.
Lambda function will make it much easier to use STL algorithms which take
a user-defined functor (such as for example for_each(), find_if(),
transform(), etc.) which will make them much more desirable. They will
also make it easier to quickly create data containers with more exotic
comparison functions than less_than or greater_than.
> I'm more interested in
> the range-based for loop (yes, I know it's pure syntax sugar), and template
> concepts.
Personally I'm drooling over rvalue references, which will allow for much
more efficient move semantics.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp wrote:
> Personally I'm drooling over rvalue references, which will allow for much
> more efficient move semantics.
My understanding is that informally, this lets you match a template or
overload where one or more of the arguments is, essentially, guaranteed
to not be aliased. Is this a reasonable summary?
--
Darren New / San Diego, CA, USA (PST)
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On Tue, 02 Sep 2008 21:13:43 +0200, Darren New <dne### [at] sanrrcom> wrote:
> Warp wrote:
>> Personally I'm drooling over rvalue references, which will allow for
>> much more efficient move semantics.
>
> My understanding is that informally, this lets you match a template or
> overload where one or more of the arguments is, essentially, guaranteed
> to not be aliased. Is this a reasonable summary?
Not really, at least not the way I understand it.
R-value references are basically just a way to bind temporaries to
non-const references. Specifically, they facilitate move constructors
which are much like copy constructors except that they may destructively
alter the source of the "copy".
--
FE
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |