Recent

Author Topic: c= a++ + b  (Read 4451 times)

ali-libre

  • New Member
  • *
  • Posts: 40
c= a++ + b
« on: October 09, 2016, 03:21:20 pm »
I want similar in pascal i tried diffrent test without success...

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: c= a++ + b
« Reply #1 on: October 09, 2016, 03:40:56 pm »
I think you need something like
Code: Pascal  [Select][+][-]
  1. c := a+b;
  2. inc(a);
if a is integer or
Code: Pascal  [Select][+][-]
  1. c := a+b;
  2. a += 1; // which is absolutely equal to a := a+1;
if a is float.
I don't think there is a way to make this in a single line. And even if it is, it'd be hard to read stuff like c++ +=a++ + --b;.

P.S. If you're trying to learn pascal while knowing c, I really recommend you to read this relatively short article: http://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html
« Last Edit: October 09, 2016, 03:46:25 pm by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: c= a++ + b
« Reply #2 on: October 09, 2016, 04:06:57 pm »
It is one of the strengths of Pascal that it doesn't support constructs like this one.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: c= a++ + b
« Reply #3 on: October 09, 2016, 06:45:27 pm »
It is one of the strengths of Pascal that it doesn't support constructs like this one.

+1 million

Bart

fred

  • Full Member
  • ***
  • Posts: 201
Re: c= a++ + b
« Reply #4 on: October 09, 2016, 06:53:01 pm »
I suppose the closest will be something like this:

Code: [Select]
function postinc(var n: integer): integer;
begin
  Result := n;
  Inc(n);
end;

c := postinc(a) + b;

Kays

  • Hero Member
  • *****
  • Posts: 569
  • Whasup!?
    • KaiBurghardt.de
Re: c= a++ + b
« Reply #5 on: October 09, 2016, 07:08:21 pm »
I suppose the closest will be something like this:[… some code here …]
Yeah, I guess so.

But, ali-libre, as jwdietrich pointed out [and bart heavily agreed], assignments with side-effects are not welcome in Pascal. The point is, debugging them can become pretty tricky.

If you encounter multiple times that situation, you should put your assignments into a procedure, keeping your assignments free of side-effects.

Wiki:Pasal for C users Prog:C-Operators compiler switch
Yours Sincerely
Kai Burghardt

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: c= a++ + b
« Reply #6 on: October 09, 2016, 08:46:54 pm »
The closest language I know that accepts that is brainfuck. Little bit unreadable, but ++++++++ all over the place ;)
https://esolangs.org/wiki/Brainfuck
hello,world! anyone? (this is actually readable to me)
Code: Pascal  [Select][+][-]
  1. ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

[edit]
Or (this is not, took me ages...)
Code: Pascal  [Select][+][-]
  1. --<-<<+[+[<+>--->->->-<<<]>]<<--.<++++++.<<-..<<.<+.>>.>>.<<<.+++.>>.>>-.<<<+.
  2.  
« Last Edit: October 09, 2016, 08:59:26 pm by Thaddy »
Specialize a type, not a var.

shobits1

  • Sr. Member
  • ****
  • Posts: 271
  • .
Re: c= a++ + b
« Reply #7 on: October 09, 2016, 09:21:45 pm »
Or (this is not, took me ages...)
Code: Pascal  [Select][+][-]
  1. --<-<<+[+[<+>--->->->-<<<]>]<<--.<++++++.<<-..<<.<+.>>.>>.<<<.+++.>>.>>-.<<<+.
  2.  
hhhh,,  :D

Quote
https://github.com/matslina/awib
* Awib is a brainfuck compiler entirely written in brainfuck.
Just how much brainfucked are they????  ;D

ali-libre

  • New Member
  • *
  • Posts: 40
Re: c= a++ + b
« Reply #8 on: October 10, 2016, 04:02:20 am »
Yes . Fred it's good idea...
i had to inc/dec one by one ever
Thanks

 

TinyPortal © 2005-2018