Questions tagged [imperative-programming]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers

Hoare triple: introducing Loop invariant and partial correctness

Hoare Triple formalizes program correctness, which contains postcondition, program and precondition such as $\vdash P \{Q\} R$ Provided code snippet: ...
Bruce's user avatar
  • 1
19 votes
11 answers

Why do functional languages disallow reassignment of local variables?

Fair warning: I don't actually know a functional language so I'm doing all the pseudocode in Python I'm trying to understand why functional languages disallow variable reassignment, e.g. ...
BatWannaBe's user avatar
0 votes
2 answers

Declarative, interrogative, imperative, and exclamative sentences in computer languages

The following English sentences have different forms (syntax): Declarative: You are my friend. Interrogative: Are you my friend? Imperative: Be my friend! Exclamative: What a good friend you are! ...
Géry Ogam's user avatar
0 votes
1 answer

Example on Referential transparency (wikipedia)

I have a rather foolish question on an example explaining the idea behind Referential transparency Here is given an example i not understand: Consider a function that returns the input from some ...
user267839's user avatar
3 votes
2 answers

Plain-language example of how a functional style makes parallel programming easier

I read a few "function >> imperative/OOP" articles because I heard there was a move in imperative OOP languages toward a functional style of coding, especially encouraging pure ...
BatWannaBe's user avatar
1 vote
1 answer

Is object oriented programming considered to be a declarative programming approach?

Is object oriented programming considered to be a declarative programming approach? On Wikipedia, it is said that OOP tries to extend the imperative programming paradigm to a somewhat declarative ...
Pat8's user avatar
  • 165
1 vote
1 answer

For every imperative function, is there a functional counterpart with identical performance or even instructions?

Currently, I haven't learned about a functional language that can achieve the same performance as C/C++. And I have learned that some languages that favor functional programming to imperative ...
Shreck Ye's user avatar
  • 145
0 votes
0 answers

Denotational semantics of command sequencing

Moved from cstheory.stackexchange upon request Winskel, in his book The formal semantics of programming languages, on page 58, writes: C[c0;c1] = C[c1] o C[c0] a composition of relations, the ...
Gergely's user avatar
  • 325
1 vote
1 answer

Is "imperative computing" just a fancy way of saying "scripting"? Or is there more to it?

Maybe this is a very ignorant question. I don't understand imperative computing very well, would it be correct to think of it as simply scripting (as in, running one or a few commands at a time, ...
James Ronald's user avatar
2 votes
2 answers

Is purely functional programming in some situations less efficient than imperative programming?

I am used to implementing algorithms in imperative languages. Many of the algorithms I have implemented use hash maps, hash sets, mutable arrays, heaps, doubly linked lists, etc. I understand that ...
juhist's user avatar
  • 273
3 votes
1 answer

Formal semantics of a mutable/imperative stack

When introducing formal semantics for data structures, immutable stacks are a nice simple example : $\mathit{is\_empty}(\mathit{create()})=\mathrm{True}$ $\mathit{is\_empty}(\mathit{push}(e, s))=\...
ysalmon's user avatar
  • 233
3 votes
1 answer

"Immediate" method of translating arbitrary mutable program to equivalent unmutable program?

Consider the following program in "mutable style": x=1 x=f(x); x=f(x); We can rewrite this in "immutable style" without changing the higher-level structure of ...
user56834's user avatar
  • 3,492
3 votes
2 answers

The idea behind the state of Imperative languages

I was reading about programming paradigms and I have a question about the state when speaking about Imperative languages. What does it mean to change the program's state? Is it just an abstract idea? ...
vesii's user avatar
  • 223
5 votes
1 answer

Best way to translate while loops to functions for software verification

I have a verification engine where while loops are translated into functional code, like this: ...
user1868607's user avatar
  • 2,230
0 votes
2 answers

Definition of "idempotence" of a function?

Currently there are two things that may change between invocations of a function: the return value, and the external states. I understand that if the external states changes, the function is not ...
Franklin Yu's user avatar
4 votes
1 answer

Can we add dependent type into an existing imperative programming language?

As we know, dependent type allows programmers to write bugless programs. But as I know there's only very few languages support dependent type, like Haskell with extensions, Idris, Agda, F*, etc. ...
ice1000's user avatar
  • 888
5 votes
2 answers

Why don't imperative languages like C or Go support Haskell-like parametric polymorphism?

Why don't imperative languages support parametric polymorphism as powerful as whats in Haskell and OCaml? More specifically if I call a function foo(x) that ...
hgs3's user avatar
  • 243
2 votes
1 answer

An imperative program is analogous to how a Turing machine works?

Since Turing machines has great influence on typical hardware architecture (Von Neumann) and both uses concept of state, is correct to say that an imperative program is analogous to how a Turing ...
Alexandre Thebaldi's user avatar
0 votes
0 answers

What is the origin of state concept?

On a Turing machine, the state changes during the execution of the program. Von Neumann architecture implements this machine theory and typical computer hardware uses Von Neumann architecture. ...
Alexandre Thebaldi's user avatar
2 votes
0 answers

What is the difference between a loop and a natural loop?

Is there a difference between a loop and a natural loop? Natural loops are defined as having a back edge to a head block that dominates it. If you have a natural loop nested inside of another ...
Victor Brunell's user avatar
3 votes
0 answers

Definition of imperative semantic in a HDL context

I've been studying from this book the topic of "Synthesis and optimization of digital circuit". In chapter 3 some theory about programming languages is exposed. I was wondering what's the meaning of ...
user8469759's user avatar
25 votes
1 answer

Does a do-while loop suffice for Turing-completeness?

I know that, in imperative programming languages, a while-do loop is sufficient as a control flow construct to make the language Turing-complete (as far as control flow goes - of course we also need ...
Martin Ender's user avatar
3 votes
1 answer

Why precondition strengtening is sound in Hoare logic

I have problem with understanding why precondition strengthening is sound rule in Hoare logic. The rule is: $$ {P \implies Q, \{Q\} C \{X\} } \over {\{P\} C \{X\}} $$ I really do not understand why ...
Trismegistos's user avatar
3 votes
2 answers

Is there a formal term for functions that have static state across executions?

Two examples, one in PHP: function adder($i){ static $a = 0; $a += $i; return $a; } A similar effect can be achieved with closures in javascript: ...
Kit Sunde's user avatar
  • 131
6 votes
2 answers

Eliminate non-local references from closure

For a code similarity detection framework I need to eliminate references to non-local variables, for example having the following closure: ...
Philip Kamenarsky's user avatar
2 votes
1 answer

Do functional algorithms require more memory than imperative algorithms? [closed]

Let's suppose we are counting words in string. We split it so what we have is an array of strings. I'll use Python as an example. The imperative approach would as follows: ...
blue-dino's user avatar
  • 199
4 votes
1 answer

Denotational semantics of expressions with side effects

I'm doing revision for a module on programming language semantics and I'm having trouble understanding the introduction of side-effects in expressions. We assume a standard syntax for arithmetic ...
user2320239's user avatar
1 vote
1 answer

Loop invariant: decreasing a variable and swapping it

As an example exercise, we were asked to find the loop invariant for this bit of code. ...
Akatzki's user avatar
  • 33
8 votes
2 answers

Isn't Functional Programming just Imperative Programming in disguise?

A YouTube video I was watching explained the differences between Imperative and Functional programming by demonstrating how the numbers from 1 to ...
CodyBugstein's user avatar
  • 2,907
1 vote
1 answer

Asymptotic time complexity of a two-loop program

I have two pieces of code in a function which I'm trying to calculate the asymptotic running time for: ...
user avatar
7 votes
2 answers

Is it possible to find the nth term of a Fibonacci sequence using a definitive for loop?

I'm using the book Introduction to Computer Science by John Zelle and at the end of Chapter 3 (Computing with numbers), I'm asked to find the nth term of a Fibonacci sequence presumably using a ...
qzxt's user avatar
  • 79
5 votes
1 answer

termination of two concurrent threads with shared variables

We're in a shared memory concurrency model where all reads and writes to integer variables are atomic. do: $S_1$ ...
Gilles 'SO- stop being evil''s user avatar
5 votes
1 answer

Double-nested loop with bitwise operation

I have this little exercise: for ( i = 0; i < 2 * n; i += 2 ) for ( j = 1; j <= n; j <<= 1 ) if ( j & i ) foo (); (...
Machta's user avatar
  • 151