Recent

Author Topic: c= a++ + b  (Read 3488 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: 570
    • My "almost daily" development blog
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 »
Lazarus 1.9 + FPC 3.1.1 Debian Jessie 64 bit.

My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

jwdietrich

  • Hero Member
  • *****
  • Posts: 1132
    • 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.0.10 | FPC 3.2.0 | PPC, Intel, ARM | macOS, Windows, Linux

Bart

  • Hero Member
  • *****
  • Posts: 3904
    • 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: 189
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;
Started with OmegaSoft Pascal on OS-9/68k , now Lazarus 2.0.8 / FPC 3.0.4 on Windows 7

Kays

  • Full Member
  • ***
  • Posts: 212
  • 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: 10449
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 »
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

shobits1

  • Sr. Member
  • ****
  • Posts: 278
  • .
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